2 Replies Latest reply on Jun 7, 2006 3:24 AM by Newsgroup_User

    PHP Form Redirect

    Level 7
      I've got a form going that I'd like to re-direct to a thankyou page. My
      code looks like this:

      <input name="action" type="hidden" id="action" value="send" />
      <input type="submit" class="submit" value="Submit" />
      <input name="redirect" type="hidden"
      value=" http://www.paramount-const.com/html/thankyou.html">

      http://www.paramount-const.com/html/contact.php

      The form field itself has this action assigned to it:

      <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
      enctype="multipart/form-data" name="ContactInfo" target="_self"
      id="ContactInfo">

      The page doesn't seem to be re-directing.

      Thanks

      Dave
        • 1. Re: PHP Form Redirect - SOLVED
          Level 7
          Dave Anderson wrote:
          <snip>
          >
          > The form field itself has this action assigned to it:
          >
          > <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
          > enctype="multipart/form-data" name="ContactInfo" target="_self"
          > id="ContactInfo">

          Seems that the idea of using a php command as the action negates the
          possible use of a re-direct anywhere else...

          This code seems to do the trick for me:


          <form action="thankyou.html" method="post" enctype="multipart/form-data"
          name="ContactInfo" id="ContactInfo">
          • 2. Re: PHP Form Redirect - SOLVED
            Level 7
            <?php echo $_SERVER['PHP_SELF']; ?>

            Will enter the name of the current page into the form action, so the page
            submits to itself. Usually you would have some code at the top of the page
            to check whether the form has been submitted, perform the necessary action,
            and then redirect

            eg
            <?php
            if(strlen($_POST['form_field']) > 0){
            // Form has been submitted

            // Perform action here

            // Redirect
            header("Location: " . $_POST['redirect_form_field']);
            }
            ?>

            Thats simplified a bit, but gives you the basic principle

            Gareth
            http://www.phploginsuite.co.uk/
            PHP Login Suite V2 - 34 Server Behaviors to build a complete Login system.