Front End Upload
3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 17 (RSS)
By moh3 - December 14
Dear CMS Builder, thank you for your wonderful software i have been using your software since 2011, any ways,
I would like to utilize uploading functionality on the front end, where a visitor would be able to create a record after submitting a form ,
Q!: Will the Form builder be able to cover this requirement
Q2: i found old threads using an upload form that submit the information and upload a file, but it is from 2022 and most probably the changes you have done on the code the complete upload functionality has changed since that date
https://interactivetools.com/forum/forum-posts.php?postNum=2245793#post2245793
By Tim - December 16
Hello moh,
The form code generator plugin doesn't support file upload controls right out of the box. However, using some of the code from the files you show you should be able to get it to work with your target table and upload. The steps are outlined below and assumes you have some basic coding skills to get it working.
- Start by creating a form that targets your desired table using the form generator plugin. If you have not seen this plugin, you can find it in our plugin section of the site. Here is a direct link: https://interactivetools.com/plugins/form-generator/
- Copy over the folder into your site's CMSB plugin directory.
- In CMSB admin, go to CMSB Setup >> Plugins and in the inactive plugin section you should see the form generator plugin. Activate it.
- In CMSB admin, go to CMSB Setup >> Code Generator and click "Form Generator". There you can target your desired database table which will have the upload field on it.
- Once you have filled out the fields, click generate.
- Copy the code to a new PHP file and save that file on your website (you can put the page in your root directory for now)
- Looking at this page you will see that there is a note to developers that upload fields are not supported. That is fine. We can go back into the page and in the HTML where it says that, you can replace it with this..
<iframe src='uploadForm3_iframe.php?table=<?php echo $FORM_TABLE ?>&field=<field name here>&num=<?php echo $FORM_RECORD_NUM ?>&preSaveTempId=<?php echo htmlencode($FORM_PRESAVETEMPID) ?>' height='150' width='100%' frameborder='0' scrolling='yes'>
</iframe>
You will notice that in this code there is a place you have to replace called "Field name here" where you will put the name of the field from your table. For example, if you called the field in your table "my_image" then you would use that name in the URL for the field.
Almost done...
- Copy the uploadForm3_iframe.php into the same directory as your newly created page.
- At the top around line 2 you will see a path to viewer_functions.php that will need to be updated to point to your viewer_functions. If your installation of CMSB is in cmsb, and you put these files in your root web directory, you can use something like...
require_once __DIR__ . "/cmsb/lib/viewer_functions.php";
- Then down on lines 14/15 of uploadForm3_iframe.php you will see a set of allowed tables and allowed fields. Put in the name of your table and name of the upload field you are targeting again. You can add more tables and more fields here if you wish this script to service multiple tables and fields. This is just for security to allow the processing of targeted tables and fields.
- Lastly, just to clean things up, you can delete the lines that tries to include 'core_head.php' and the line down around 200 which echos the $preSaveTempId. I am guessing these are implementation specific and for debugging.
Once you have followed these steps, you should then be able to visit your page again and see a box to upload images, select an image and submit the form to have a new record created in your table with the image uploaded.
If you wish to upload other file types, you will need to make sure the CMSB upload field you have in your table has the added file extensions. You will see them when you modify the field.
I hope this helps! If you continue to run into problems, you can reach out to us on support and we can look at giving you a quote to hook up the fields.
Enjoy! :)
Senior Web Programmer
Interactivetools.com