I have already asked a question regarding this issue here, for a client project. Those answers may not be what I am looking for, so I will try to make this question as detailed as possible.
I have a form which has 4 main pages. The first page asks for personal information. Clicking on Submit takes you to a second page. Second page has a dropdown list containing item numbers. Let’s say they are A, B, C, D, E.
When a visitor chooses an item and clicks submit, I want the next page to show content based on the item chosen above:
- If visitor chooses option A, the page should load the html page a.html or php page a.php.
- If he selects option B, the page should load the html page b.html or php page b.php. And so on for other items, each one having a different page.
I don’t know PHP in detail. I am building this form in a website on WordPress.
You can get around this problem in many ways, but in this case I would recommend two ways: PHP or JS.
Solution 1, PHP
You will need
1) A form
2) A PHP handler
Solution 2, Javascript
Let’s say that you’d like to display different pages without using PHP, then what to choose? JavaScript. This is, to me, more easy to implement and much more “user-friendly” :
Task: Display different pages from the same form
It is usually better to dynamically change the content via echo-ing different html, but this can be achieved through headers.
Just be sure not to output ANYTHING before the header calls or it will not work properly. Running PHP commands etc are fine as long as no html is sent to the client before you do your redirect.
Another possible solution is to use an iframe to load the next page, one benefit of this is that you can do it all in JS
You can use an AJAX function to achieve the above mentioned result. Now we are in second page which has a drop down menu.
And in the onchange property of the dropdown, I’m calling an AJAX function
selectpage()
, to which I pass the currently selected value from drop down…SO based on that value, appropriate page will be loaded & shown inside the showpage div.And in those corresponding, pages…..echo whatever you want to echo.