I'm putting together a 4 step registration form, which at the end will redirect the user to Paypal and enter the entire form contents into the database.
At present I have the following flow:
Page 1 - Enter Details
Click Submit (POST)
Page 2 - Check page 1 Details
Page 2 - Put details into $_SESSION
Page 2 - Enter more details
Click Submit (POST)
Page 3 - Check page 2 details
Page 3 - Put details into $_SESSION
Page 3 - Enter more details
Click Submit (POST)
Page 4 - Check page 3 details
Page 4 - Process all data and put into DB
Page 4 - Redirect to Paypal
Page 4 - Listen for success before setting flag to active in db
DONE
My question is, am I going about this the right way? Although it works fine I've had to use jquery hacks to enable users to go 'back' at any stage to make changes to the form.
I was considering using hidden fields instead of SESSIONS so that each step would resubmit all of the data, and I could back-POST all data to a previous page if the user wanted to go back a step. I think there might be more chance of the user loosing their data this way though?
Hidden fields concept will make things difficult to manage...in case if the number of fields are more.
Its better to use session in your case instead hidden fields.
It depends : do you have the need to do a POST after each step ? If not, you could aswell just put all steps in your page, each in a fieldset, and display only 1 fieldset at a time in javascript (as you're talking of jQuery). This way only the submit button on the last step would submit the whole form
On the other hand, if you need to have a post after each step, I would choose the session approach, which is more secure
Related
I have 2 forms, both of them are divided in 2.
First time I ask for name, email, phone and company than I have 2 buttons continue and call me
Some of them may not click continue button so I need to get this details before they run away from the page.
I need the form to do an auto save when all fields are completed even if user is not submitting the form.
How can I do this with contact form 7 or formidable forms?
I'm open to new suggestions too, other plugins etc..
Thank you.
u can try this plugin contact form 7 AutoSaver ,
Select some forms to enable auto-save on them, meaning when a user fill the form, without even submitting it, then navigates to another page and comes back or refreshes the page, they will see the data they previously filled still available for them!
https://wordpress.org/plugins/cf7-autosaver/
I have a multi-step form that I have spread across 4 separate pages - in other words, 4 sections (I chose this method as it would be far too complex to process all my fields on one page). In my MySQL DB I have a table for each of the sections on each page (step1, step2, step3, step4). After submitting the first page I would like to insert my Page1 data to the DB and have it return the Primary Key, which I aim to then post to the next page (step2.php) ... and the same process will follow for Step3 and Step4.
The tables for Step2, Step3 and Step4 in the DB all have a Primary Key (reg_id) which are also all Foreign Keys to step1.reg_id.
I would like some advice/suggestions please on how to:
Post data back to my DB after each page submit (Do I post back to the same page, or have a separate processor page to handle that?)
Redirect to the next page
Pass the reg_id returned from Step1 to the Next Step pages
I am using plain and simple PDO to get my data in MySQL. I admit that I don't have a lot of PHP knowledge to accomplish this as I am too used to the lifecycle of ASP.NET webforms development, hence my asking for your expertise here.
Much appreciated as always!
As Karl said in his comment, it makes the most sense to save the form values as $_SESSION values before redirecting to the next page. The form processor then accesses the values from $_SESSION, just as if you had sent them as $_POST values.
To expand a bit on why this is a bit better, you have to think about what would happen if your users don't just go from page 1 to page 2... to the end of the form in one sitting. What if someone exits the wizard partway through? What if they need to go back and edit values, sometimes multiple times? In short, if your users have a workflow that results in either incomplete forms or the user going back and forth between form pages, you might end up with an awful lot of unnecessary validation and writes to the database.
If you save the form values in the session and only store them in the database when the user completes the entire multi-page form, you remove the possibility of these unnecessary writes to the database.
It also makes it easy for people to go backwards in the form to make edits without breaking your validation which you've indicated is a bit complicated. Ex. suppose a value x on page 1 is related to a value y on page 4. The user gets all the way to page 5 but then decides that they want to go back to page 1 to edit x. Page 1 has access to the session, and therefore has access to both x and y -- you could, for example, warn them if their new x value would make y invalid, or something along those lines.
You can either have 5 seperate pages for this, and pass data between them all.
Page1.php would have the initial form but do no processing, it posts all of its data to page2 onSubmit.
Page2.php would retrieve all the post data from page1.php, store into a database, and retrieve the ID of that and then display a form for the second stage of the wizard. This form onSubmit, sends the ID (in a hidden field) and the form elements to page3.php
Page3.php stores the post data from page2.php, retrieves the ID and displays the next form. Again submitting the hidden ID and form fields, this time to page4.php
You can repeat this step as many times as you have steps in the wizard.
The other way to do this is to have it all in one page. There will be several if statements, that read what data has been sent. A hidden field will keep track of the current step. i.e.
if $step == 1, display the first form (onsubmit sent $step = 2 as hidden field)
if $step == 2 retrieve post data from first form and insert into DB then display the second form (onsubmit send $step = 3 as hidden field)
if $step == 3 retrieve post data from previous form and insert into DB then display the second form (onsubmit send $step = 4 as hidden field)
and so on
i got 4 pages which are company details, job requirements, job responsibilities and design. so im gonna update the data from these pages. so i retrieve the data from database to be display into form for these 4 pages. after i edit the values on first page, then i go to next page for next update. but when i go back to previous page, the data wont keep the edited value but display the old data that i retrieved from database. so how to prevent this to happen ? same goes if i refresh the pages. i know i can use the session to store edited value but still i think that form will display the old data. help me give the idea how to do this pls ! thanks
You need to follow below steps
Go to next page by submit & action attribute
In next page hold all the post value into hidden fields
Use a back button to go back.
when go button will be pressed submit the form which is holding the hidden fields
Now you are in first page and simply use $_REQUEST or $_POST to get the previous value.
Hope you under stand.
N.B: If you use browser back button browser will ask you to confirm to resubmit the form. If you confirm then no problem but if you didn't confirm then you lost your values.
I'm developing an application in mobile view using CakePHP, where there's no Javascript code can run.
My scenario:
In user login form, users clicked submit button. But before the data submitted and users go to the next page, I make an 'interruption' page (renders a new view). In there, contains "Facebook" and "No, thanks" button. When they click "Facebook", they will connect their Facebook accounts. But, if they click "No, thanks", the login continue.
My question is, how can I make that "No, thanks" button? Because if I use <input type="submit"> button, the form that contain its data is in previous page, so this button will not be clicked. And, how to store POST data, and when that "No thanks" button clicked, then, the data submitted?
You can either store the data in session, or you can make the "no thanks" button the submit button of a form where all the data from the previous page is stored in hidden form fields.
Personally for a number of reasons, I would prefer to utilize sessions, but since you are even asking this question, I am guessing you are unfamiliar with usage of session data.
A simpler question would be:
To make these two forms on single page but with LOTS of vertical or horizontal space in between user login form & 'interruption' page so user seeing the login form can't see interruption section although both are within same <form></form> tag. Then, the the submit button is simply a link to interruption section of the same form. this link is simple an <a> tag with inline linking, which would hide the login form & display interruption page without needing javascript. similar to links to Go to Test Section A on this page
http://www.dynamicdrive.com/dynamicindex5/bookmarkscroll.htm
Further then in the interruption section you can use a real submit button which makes a POST back to request the server.
[edit]
This workaround is based on assumption that user doesn't scroll far enough. Because most users won't, making it 1step process for them instead of 2process which is specially important on mobile. And if somebody does then the empty form gets submitted to the server & then we can run validation & return a error to the user. where he/she can fill the complete form. so This is a good workaround better than storing the data in session & making two POST request for every user login over mobile network which are generally unreliable.
A better solution might be just to combine both forms into one form. Then you don't have to make 2 http requests. Maybe all you need to do is to add one extra button to the original form "Login with FaceBook" next to the other submit button.
I thought hours about that problem but I didn't come to any conclusion. My problem here is that I need a 'Previous' Button added to a form. The user should fill out a formular that is splitted up in 13 parts. Every part is an own formular having a 'Next' button for submitting everything to a database and redirecting to the next page.
How do I integrate a 'Previous' button there? ...
I don't if it might be usefull for you to know that I'm using cakePHP, and well I'm pretty new to it.
Store the POST data of each form and the current form index in your session.
When clicking the back button, open form (currentForm - 1) (if that's a valid form index) and populate the fields with formData[currentForm] (assuming currentForm is now the form the back button redirected to)
The question really is, do you want to store each stage of the formula in a record? or do you want to store every stage of the formula in the "transaction"? The difference here is important. What is your relationship with the user? Do they login? are they anonymous? How do you associate their answers from one form entry to the next? If you store each entry in the database, in some chronological way, then simply populate the previous form with the previously entered values; when they click previous. If you do not store the entries and instead utilize a session to retain values between "next" clicks then populate the "previous" form with those values.
I've coded a similar form in classical ASP, see if you can make it work in CakePHP:
I had a 7 step form, step 2-7 have previous buttons. Each step consists of one asp script. All scripts post back to themself. I check the REQUEST_METHOD upon every invocation of the script to see if it was called by GET method or POST. If POST then data is validated, if validated then it is saved. There are three submit buttons on forms that allows user to choose whether he wants to just save the data, save and move to next step or save and move to previous step. Depending on which button was clicked, the user is "redirected" to the previous/next page. This post specifies how to add and handle the previous/next buttons:
Multiple Submit Buttons — Specifying default button