views:

791

answers:

4

Hi,

This is my first post, so be kind ; )

I'm wanting to create a multi page form with php.

The form will spread over 3 pages, each page will need to validate on the data entered into the form on the client (using jquery validation) and if javascript is disabled, on the server, where error messages need to be displayed beside the related form field.

Upon validation, the data needs to be passed to the next page in the form, preferable using session variables.

The main problem I'm having is that most validation scripts now leave the action="" as being self referring to the current page, and as such post variables cannot be passed onto a different page in the chain of forms.

I want to have a validation script that will validate, and then post to a new page upon clicking the submit button.

Thanks

Peter

+2  A: 

You don't have to post to the next page.

You can validate the form fields on the current page, store them in a session, then use a header("location: nextPage.php"); exit(0); redirect to go to the next page.

John Rasch
+1 This is the right way to do it.
Byron Whitlock
Thanks for this, on reflection, this is the best approach! Cheers.
mathalete
A: 

I reccommend this JS validator. Very easy to use and doesn't depend on the action="" parameter at all, so you can still set it to whatever you want.

Shadow
A: 

generally, you can do something like

<form onsubmit="return validateForm();" method="post" action="/wherever">

And this will call your javascript validation form, not submitting the form if the validation form returns false.

You will also need to do server side validation, and I suggest that you store the previous forms validated results into the session, rather than re-posting them (as these wont have to then be re-validated each time!)

Mez
A: 

You should use the post redirect pattern. Post the variables to the next page (control page), If validations pass then that page does a

header("Location: /page2.php");

after saving the posted variables to the session. If the server side validation fails, then you do a header to the page1.php with the error. pThis way you can use your back button.

Byron Whitlock