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
Related
I have a base php file that displays items in a database on an html table. Each row has a remove button. When pressed, it will remove that one item from the database. At the end of the table, there is an add button that once it is pressed will take you to another php file with a form that you can fill out with information to add to the database. I am having two problems. The first is that I am not sure how to determine what remove button is pushed. My second question is how do I move to a different page for the other php file once the add button is clicked? I am not supposed to use AJAX for this. And though I tried using include and isset, I couldn't get them to work properly. Any help, conceptual or code examples would be greatly appreciated.
If you can go to other pages, simply create a form with a hidden input field holding the id of the row and have the remove button be a form submit button.
On the remove button being clicked it will go to the delete php file and redirect back to the table page.
As far as the adding button, instead of using a button just use a link to the add form.
If any of this doesn't work because of requirements you haven't mentioned let me know of any restrictions you have.
For your first problem, just make a form for each individual row of data. that way, you will be able to pass by post the relevant id you want to remove.
Another way would be to create a "button" (not a submit button) and have the relevant onClick="..." script - like redirect to "index?Action=Remove&Id=xxxx"
By making different form for each button, you add button will have its own "action" in the form and you'll be allright!
You either have to generate a new "form" (with proper html) if you need to pass data to your next page. If you only need to redirect depending on which button you press, you can have a onClick="..." event on your button. Make sure not to make a "submit" button :)
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 have a form with multiple tabs. Each tab has various items (textboxes, radio buttons, drop down boxes). I need the content to be saved after 15 seconds idle or when the user clicks on a different tab/item.
Currently I am saving when the user clicks on a button. This is giving the problem that if the user is on tab x and clicks the button, the form is taken back to the first tab.
I would prefer to have the save button on the last tab. When the user is filling in the data in the different tabs, it is automatically being saved. When the user clicks on the last tab, the command button is shown and then upon clicking another save is performed and the user is taken to the main screen with all the records.
Your advice and guidance please :)
Regards,
Babu
I'd say you want to submit each tabs content (form values) using an ajax call in background when another tab is selected. That way you can have the user navigate between tabs without having to reload the whole form. And the values are handed over to some ajax endpoint on your server where they can be stored.
You can do the same for an autosave feature: set a timer, when that triggers you use an ajax call to post the form values in background.
To make your life easy use jquery for the ajax calls and jquery-ui for the tabs.
You dont save the previous tab datas until you save the datas in last tab.. because if user is not willing to save the data after moving to last tab mean.. it is waste of saving previous data and deleting it..
So you can do it in SESSION... (i.e) you store the datas of each tab in session with one session ID as
$session[ID][fieldName1]
$session[ID][fieldName2]
$session[ID][fieldName3]
finally if the user click on that last button tab.. you get the datas from session and save in database USING AJAX and unset the session variables.... unset it if he clicks cancel also.....
You can also use Jquery tabs so that the complete form is on one page and the form can be saved on the last tab (with your button).
This way you don't have to worry about your data being saved until the last tab.
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 have a page with two forms that is generated with PHP.
The first part contains text boxes, a submit button and a clear button.
The second form is just a button called "Add more text boxes" so the user can add more to his form if he needs to.
The problem is when I click the "Add more rows" which loads another page which changes a value.
This value then affects the original page when it reloads causing more text boxes to get created.
The problem is that I lose all the data that was entered.
Is there any way to preserve the data when the user clicks "Add more rows"?.
Here's a screenshot of my page.
Thanks
If you want to do it without js than you put all in one form. When you click button to add row all entered data will be available in $_POST or $_GET so you can fill form with existing data and add a row when generating new page.
Ideally you should use javascript to dynamically add new rows w/out making new requests to the server and loading new pages. But if you want to keep it javascript free. If it's all the same php script just controlled by conditions, just use the $_POST['variable'] values as the value="$_POST['variable']" in your fields. If it's handled through multiple scripts, you can use a session variable to pass the data from one page to the next.