Merlinox Posted July 30, 2006 Share Posted July 30, 2006 Hello,I manage to do 2 forms in 2 diferent php files.1 form in each page.The 1st one has a form with a basic contact info and an attached fileand the second form has a list of questions with checkboxes.In the first form I have 2 buttond (reset and continue) and the second form also has 2 buttons (reset and send).After sending the information everything is send to an email.My only problem now is that I have to validate first the information put in the first form and then display the second page with the second form.This is what I did:Th first form1.php has the following:[code]<form action="acghsformv3f2.php" method="get" enctype="multipart/form-data" name="form1"> <!-- The questions of the form --> <input type="submit" name="Submit" value="Continue"></form>[/code]And in my second form2.php I have the following:[code]<body><?php if ($_SERVER['REQUEST_METHOD']=="POST") { // In here I put the validations of the second form. // If I put the validation of the first form they will occur after the second // form is process (notice the POST) and I need them to occur after the first // form and before opening the second form. // But if I put something similar in the first Form then the second will never // be open because I will have to change the action and method of the // first form. // // I HOPE THIS IS CLEAR ;-) // If validations are ok send an email } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form2"> <!-- The questions of the form --> <input type="submit" name="Submit" value="Submit"> <?php // This is what will capture the values from the first form and put them // in hidden fields to be send after. Notice that it must be inside the form. $name; // Represents the name of the elements in $HTTP_POST_VARS $value; // Represents the value of the elements in $HTTP_POST_VARS // Do while there is an element in $HTTP_POST_VARS... while (list($name, $value) = each($HTTP_POST_VARS)) // Construct a hidden input field. // Then go back to the beginning of the loop and do the same thing. { echo "<input type=\"hidden\" value=\"$value\" name=\"$name\">\n"; } ?> </form><?php} ?></body>[/code]So, as you can see this is my logic of what I have to do but don't know how.the logical flow should goes like this: Form1 (form1.php) * If the request isn't a form submission, show the form. * If the request is a form submission, validate the submitted parameters. * If the submitted parameters are invalid, show the form again. * If the submitted parameters are valid, open second form. Form2 (form2.php) * If the request isn't a form submission, show the form. * the values from form1 are stored in hidden fields in the form2. * If the request is a form submission, validate the submitted parameters. * If the submitted parameters are invalid, show the form again. * If the submitted parameters are valid, send everything by email.Thanks again... Link to comment https://forums.phpfreaks.com/topic/16040-multiples-forms-validation/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.