The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.28 (Linux)
|
Re-Edit Form? - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17) +--- Thread: Re-Edit Form? (/showthread.php?tid=225) Pages:
1
2
|
Re-Edit Form? - spenny - Jul 26th, 2009 I have a very complicated form (multi-page form using the API) which some users will not fill out all in one go. Instead they will need to complete it over a few days. I’d like to know if it’s possible for someone to submit the form on say a Monday and then the following day log in with a user name and password and continue editing it. I’ve had a look at the Submission Accounts module but don’t think this is suitable because I can’t use it with the original form I have created. Is this right? What I was hoping was there there’s a way that I could use one of the API functions to re-load all the $fields values for a submitted form so that the user could then re-edit the form? Thanks in advance. RE: Re-Edit Form? - Ben - Jul 28th, 2009 Hi Spenny, Sure! Actually I do this very thing for a few clients. I wrote the Submission Accounts module because people generally aren't that technical and it allows for this functionality without delving into any PHP - but it's NOT a perfect solution, I'll be the first to admit. And yes, you're right - the module doesn't use the original form. If you're interested, post me back and when I get home tonight I'll locate some code for you. If memory serves it's not TOO tricky to get up and running; but it will require you a separate login form for your form. I'll explain that later... - Ben RE: Re-Edit Form? - spenny - Jul 29th, 2009 Hi Ben, That's sounds perfect! I'd be most grateful for the code that allows this. While I am not an expert PHP coder, I'm cetainly willing to have a go at configuring some code and setting up the login form. Kind regards Spenny RE: Re-Edit Form? - Ben - Aug 1st, 2009 Ah yes! Thanks for the reminder. Let me try and find an example now... - Ben RE: Re-Edit Form? - Ben - Aug 1st, 2009 Alright! Here we go. I've tried to abstract away most of the details so you can just drop it into your own form with only a few minor changes. Not sure if it'll work precisely as planned, but let's give it a go. What you need to do is add a new login form, say "login.php". This should contain the following - obviously you can separate the PHP and HTML if - I just stuck it a single file for this example for convenience. The idea is that all users going to your form will be faced with a login form off the bat. New users who haven't registered yet can use the default password (usually I just display it on the page). Existing users can log in with their own password - which they would have changed on page 1 of your own form. Well, code first. Explanation below: PHP Code: <?php 1. Update this line to point to your own api.php location: require_once("$folder/../admin/global/api/api.php"); 2. Set the $form_id to your own form ID. 3. Change these three fields to store the database column names of the fields that are going to act as the user's login username and password. In order to uniquely identify the user for when they log back in, these two are required. I always use "email" as a username field - simplest that way. $username_field = "attendee_email"; $password_field = "password"; Also: I'm pretty sure the code requires your form fields to have the same database column names. I.e. your email field has a name attribute of "attendee_email" AND your database column for that field has the same value. I've always done this - had a 1-1 relation between form field names and database column names. It just makes working with the database that much simpler. You don't HAVE to do this, but you may have to review the code to ensure it's all okay. 4. The default password. The form I was taking this from required a default password for all new users to log in with. Once they were logged in, they could change it. If you don't need this feature, just change it to some long, indecipherable string. $default_password = "pass123"; 5. Change these lines to specify the first page in your form (there are two lines like this): header("location: step1.php") 6. On the first page of your form you'll need to add the option to change the default password. All this requires is adding a field to your Form Tools form with the name attribute the same as specified above. And secondly, you'll need to add it to Form Tools so the information is actually stored in the database. And I think that's it... Hope this is somewhat helpful & not too unclear. RE: Re-Edit Form? - spenny - Aug 5th, 2009 (Aug 1st, 2009, 9:28 AM)Ben Wrote: Also: I'm pretty sure the code requires your form fields to have the same database column names. I.e. your email field has a name attribute of "attendee_email" AND your database column for that field has the same value. I've always done this - had a 1-1 relation between form field names and database column names. It just makes working with the database that much simpler. You don't HAVE to do this, but you may have to review the code to ensure it's all okay. Ben, Many thanks for this code and your detailed instructions. I've managed to use the login.php form to successfully log in and take me to the first page of my form. However when the form opens it doesn't load the data into the $fields array as I was hoping. I think this is because the array data loaded from login.php uses the field names taken from the database columns eg col_1, col_2, col_3 eg Array ( [col_1] => John [col_2] => Doe [col_3]=> 34) whereas the $fields aray uses field names from my form eg Array ( [first_name] => John [last_name] => Doe [age]=> 34) I think this is what you refer to in the above quote - is that right? If so, how do I fix this? Do I need to manually change all the column titles in the database to match my form (a very long process!!) or is there a way to change the code of formtools so that when I first initialise my form it automatically uses the field name on my form for the column titles instead of col_x? I hope I have made sense! Thanks again RE: Re-Edit Form? - Ben - Aug 6th, 2009 Ah! Good point - I forgot about that. Actually, it's really easy to map the form names to your database col names. Just log into Form Tools, edit your form and go to the Database tab. There, click on the "Smart Fill" button. That will rename all of your form fields to make them identical to your form fields. I think maybe I rely on that & kinda forgot that I did... The only potential problem is if your form field names are MySQL reserved words. In that case, the JS "Smart Fill" option will append a prefix or suffix to the generated field name... I forget which. Good grief, I'm forgetting everything today. Anyway, give that a go. - Ben RE: Re-Edit Form? - spenny - Aug 11th, 2009 Hi Ben, That's brilliant! That SmartFill Button works like magic. And now to the next problem... (sorry!) When I login I am taken to the form that I have previously submitted so that I can continue editing it (so far so good...) The problem is that because this form has already been submitted, when I submit the form again it returns error #302 - the form has already been finalized. I think I have found the code in the api.php file that checks whether the form has been finalized. The code starts on line 616 PHP Code: // check the submission ID isn't finalized Thanks again! RE: Re-Edit Form? - Ben - Aug 15th, 2009 Hey Speny, Ah! That's fine - actually no, don't delete it. Instead, just add a new key-value pair to the $params you're passing to ft_api_process_form (the last row - ignore the other rows, they're just to show the context & are probably different for you): PHP Code: $params = array( The "may_update_finalized_submissions" setting will override the default behaviour & allow you to update a finalized submission. Hope that helps! - Ben RE: Re-Edit Form? - greatwhitebuffalo - Dec 9th, 2010 edited |