Skip to main content
Known Participant
May 12, 2011
Question

registration form submission

  • May 12, 2011
  • 1 reply
  • 1437 views

i have a registration form, which checks for errors before the form is submitted.  i was told then to use an if else statement to submit the form on the same page, but i would prefer to have the user go to a confirmation page instead.  i have the form submitting to itself to check for errors.  any ideas as to how i can do this?

This topic has been closed for replies.

1 reply

nickentin
Participating Frequently
May 12, 2011

Should be simple enough.

<?php

     if(isset($_POST['submit'])) // when your submit button has name="submit"

     {

          // code for your confirmation page

     }

     else

     {

          // code for your page with the form

     }

?>

Nick

Known Participant
May 13, 2011

here is how i modified the code:

<?php
     if(isset($_POST['register']) && empty($errors)) // when your submit button has name="submit"
     {
         echo "the form will have been submitted!";
     }
     else
     {
         echo "registration form displayed here...";
     }
?>

i want to make sure that the user did not leave any empty fields.  but i get "  the form will have been submitted" when i submit it with empty fields....

nickentin
Participating Frequently
May 13, 2011

I would recommend condensing the code to something like this:

<?php
     if(isset($_POST['register']) && !empty($_POST['field1']) && !empty($_POST['field2']) ... ) // when your submit button has name="submit"
     {
         echo "the form will have been submitted!";
     }
     else
     {
         echo "registration form displayed here...";

     }
?>

Where the registration form code would look something like this:

<form method="post" action="self.php">

     <input type="text" name="field1" size="20"><?php if(isset($_POST['resubmit']) && empty($_POST['field1'])) echo "This field must be filled out."; ?>

     <input type="text" name="field2" size="20"><?php if(isset($_POST['resubmit']) && empty($_POST['field2'])) echo "This field must be filled out."; ?>

     ...

     <input type="hidden" name="resubmit">

     <input type="submit" name="register" value="Register">

</form>

Obviously, you would want to add in any formatting things (like tables, divs, etc), but this should work code-wise.

Nick