Page one.php has a form with a "Next" button that submits the data to the controller and then redirects to page two.php
On page two.php at the bottom of the form there is a "Previous" button that I want to still save the data but go back to page one.php and also another "Next" button that saves the data and then redirects to three.php and so on.
In Laravel is there a way to do this without duplicating controllers and making it more complicated?
In addition to the buttons there is a navigation menu that would have the same pages so if the user modifies any data they could also click the nav button and then data would be submitted and then go to that next page that they clicked. Is this possible or do I have to have ajax contently listening for form input changes and then posting them to the controller?
Make use of sessions. Store the data in session and on every page check if session var exists. After user submits form, empty the session
https://laravel.com/docs/5.1/session#basic-usage
Related
Click button -> go to form
Page 1: Form
Page 2 : Form - > submits information from both pages
page 3 -> completion page after form is submitted
I want to stop users from just pressing back and going to the second page. They have to go and click the button to submit a new form .
You should apply this Post/Redirect/Get method to prevent user to go back to 2nd page.
There is specific page to understand the PRG
There is also a way to keep the post data if you need it. You can see from this SO link.
i have a form. In the action field i have given a page location where the control should redirect after submit. But i want to redirect to multiple page after submit. And the next page should open in new tab. I know about target_blank option. I just want to know how to redirect to multiple pages after submit. Thank you.
You can use this script in your submit form page
<script>
window.open('link','_blank');
</script>
What do you mean by redirect?
Do you want the submit button to send form data to two pages?
If yes this can be achieved by using session variables and opening a new window on the redirected page.
1) save the form data in session variables.
2) load the 1st page
3) use php script or you can use window.open("url") in the 1st page to redirect to a new page on a new tab.
I have a multi-page form. Each page posts data form one to the next, where PHP stores the POST data as Session data. At the end of the table this session data is displayed in a summary table before final submission stores that session data in a MySQL database.
There are two ways to navigate away from a form page: both options to submit the form data.
1) The submit button which performs the form action, and navigates the user to the subsequent form page.
2) A page menu, from where the user can land on any other form page. I use JavaScript on the menu navigation to prompt submission:
$('#menu a').onclick {
$('#myform').submit();
});
However the submit action of the form is:
<form id="myform" method="post" action="?page=survey-2">
...form fields...
</form>
So instigating submit only posts the updated data to the subsequent page.
In the use-case: user fills out form, arrives at summary page, sees and error uses the menu to navigate back to a page, alters it and uses the menu to jump back to summary page: nothing changes, obviously because the updated data is ONLY being submitted to the following page, NOT the destination of their navigation.
Is there a way I can use js (or anything) such that when a link is clicked in the menu, the DESTINATION of that navigation link, also receives the form data? Or alternatively, that the action of the form can submit to all the pages at once (but default navigation is to the subsequent page only)?
Thanks for your consideration
Use AJAX to post the data to the handler, then go wherever you want to go with the callback
$('#menu a').onclick {
var data = $('#myForm').serialize();
var handler = '?page=survey-2';
$.post(handler,data,function(){
window.location.href='http://www.google.com';
})
});
For more about jQuery POST:
http://api.jquery.com/jQuery.post/
I am trying to build a web app like this using php, it has two pages:
select.php has some radio buttons in a html form for users to choose. and there is a submit button post the form to a confirmation page.
confirm.php echos the summery from previous page and there is a "back" button allow users to change their selections in the previous page.
In this point, when I hit the "back" button and previous page restored, I would like all my previous selections displayed. (more clearly, if I chose a radio button and submit in select.php, I want the radio button still being chose after I go back to select page by hitting "back" button from confirm.php page.)
Please give me some idea about how to do this kind of restore page thing.
Save your selection in session.
In select.php pre-select the radio buttons if its found in session.
BTW, You should not rely on back button of browser. Create you own back button on confirm.php page. This back button will go to select.php using no history.back()
The HTTP-Protocol is stateless.
So when calling select.php the server doesn't know anything about your previous selection.
You can either save the selection in the session or in a cookie and restore in in selection.php
Actually I have to create one page that is showing all employee information like (name,age,salary,etc) and one add button. If i clicked on add it will open one pop up window which will take user input of (name,age,salary); after submit it will update my database and my first page without refreshing the page.
i have created 3 file.
1) Display.php where i have to display employee information and add button.
2) Add.html i passes this file to popup method on click of add button.
3) Update.php where i wrote database query on action of submit button.
Now i am confused where i should write Ajax ? that will help me to display the record on my first page.
Thanks in advance.
You only need 2:
Display.php in here you display the info and add button, have a seperate <div> that is hidden but shown with anonClick javascript function. In this div you have your submit button which will fire the ajax query.
2.Update.php This will receive the ajax query and return the new data to the first page.
You can put the javascript functions in their own file and call them into display.php if you want.