16 Replies Latest reply on Jun 7, 2006 11:28 AM by Newsgroup_User

    PHP Form Redirect - Second attempt

    Level 7
      In an earlier post, I thought I had this solved, but I don't.

      My code looks like this:

      <input name="action" type="hidden" id="action" value="send" />
      <input type="submit" class="submit" value="Submit" />

      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">

      I can get the comment page to redirect to the thankyou.html page by
      substituting the <?php echo $_SERVER['PHP_SELF']; ?> command with the
      URL of the thankyou.html page itself. However, then the mail stops
      working....

      Is there a way to either assign another hidden field that will
      re-direct, or perhaps modify the form action code to redirect?

      Thanks

      Dave
        • 1. Re: PHP Form Redirect - Second attempt
          Level 7
          Dave -

          You need to add a header to the PHP code. After you validate the contact
          page against itself and after the e-mail is sent using the mail$() command,
          add a header to redirect to the thankyou.html page -

          It could look something like this:

          mail$(blah,blah,blah,blah)
          header("Location: http://www.example.com/thankyou.html");
          exit;

          --
          Shane H
          shane@NOSPAMavenuedesigners.com
          http://www.avenuedesigners.com

          =============================================
          Proud GAWDS Member
          http://www.gawds.org/showmember.php?memberid=1495

          Delivering accessible websites to all ...
          =============================================


          "Dave Anderson" <Dave@DaveandHolly.com> wrote in message
          news:e64h89$kat$1@forums.macromedia.com...
          > In an earlier post, I thought I had this solved, but I don't.
          >
          > My code looks like this:
          >
          > <input name="action" type="hidden" id="action" value="send" />
          > <input type="submit" class="submit" value="Submit" />
          >
          > 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">
          >
          > I can get the comment page to redirect to the thankyou.html page by
          > substituting the <?php echo $_SERVER['PHP_SELF']; ?> command with the URL
          > of the thankyou.html page itself. However, then the mail stops working....
          >
          > Is there a way to either assign another hidden field that will re-direct,
          > or perhaps modify the form action code to redirect?
          >
          > Thanks
          >
          > Dave


          • 2. Re: PHP Form Redirect - Second attempt
            Level 7
            Whoops - typo: mail(blah,blah,blah,blah)

            --
            Shane H
            shane@NOSPAMavenuedesigners.com
            http://www.avenuedesigners.com

            =============================================
            Proud GAWDS Member
            http://www.gawds.org/showmember.php?memberid=1495

            Delivering accessible websites to all ...
            =============================================


            "Shane H" <shane@NOSPAMavenuedesigners.com> wrote in message
            news:e64n91$rpu$1@forums.macromedia.com...
            > Dave -
            >
            > You need to add a header to the PHP code. After you validate the contact
            > page against itself and after the e-mail is sent using the mail$()
            > command, add a header to redirect to the thankyou.html page -
            >
            > It could look something like this:
            >
            > mail$(blah,blah,blah,blah)
            > header("Location: http://www.example.com/thankyou.html");
            > exit;
            >
            > --
            > Shane H
            > shane@NOSPAMavenuedesigners.com
            > http://www.avenuedesigners.com
            >
            > =============================================
            > Proud GAWDS Member
            > http://www.gawds.org/showmember.php?memberid=1495
            >
            > Delivering accessible websites to all ...
            > =============================================
            >
            >
            > "Dave Anderson" <Dave@DaveandHolly.com> wrote in message
            > news:e64h89$kat$1@forums.macromedia.com...
            >> In an earlier post, I thought I had this solved, but I don't.
            >>
            >> My code looks like this:
            >>
            >> <input name="action" type="hidden" id="action" value="send" />
            >> <input type="submit" class="submit" value="Submit" />
            >>
            >> 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">
            >>
            >> I can get the comment page to redirect to the thankyou.html page by
            >> substituting the <?php echo $_SERVER['PHP_SELF']; ?> command with the URL
            >> of the thankyou.html page itself. However, then the mail stops
            >> working....
            >>
            >> Is there a way to either assign another hidden field that will re-direct,
            >> or perhaps modify the form action code to redirect?
            >>
            >> Thanks
            >>
            >> Dave
            >
            >


            • 3. Re: PHP Form Redirect - Second attempt
              Level 7
              Shane H wrote:
              > Dave -
              >
              > You need to add a header to the PHP code. After you validate the contact
              > page against itself and after the e-mail is sent using the mail$() command,
              > add a header to redirect to the thankyou.html page -
              >
              > It could look something like this:
              >
              > mail$(blah,blah,blah,blah)
              > header("Location: http://www.example.com/thankyou.html");
              > exit;
              >


              Shane,

              Not sure I follow...

              The bottom of my PHP code looks like this:

              $message .= "Phone: " . $_POST['frmphone'] . "\n";
              $message .= "Comments: " . $_POST['frmcomment'] . "\n";
              $to = "admin@myurl.com";
              $subject = "Web Contact Form Inquiry";
              $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
              $headers .= "X-Priority: 1 \r \n";
              $headers .= "X-MSMail-Priority: High";
              mail($to,$subject,$message,$headers);
              }
              ?>

              Based on what I'm understanding, I changed it to this:

              $message .= "Phone: " . $_POST['frmphone'] . "\n";
              $message .= "Comments: " . $_POST['frmcomment'] . "\n";
              $to = "admin@myurl.com";
              $subject = "Web Contact Form Inquiry";
              $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
              $headers .= "X-Priority: 1 \r \n";
              $headers .= "X-MSMail-Priority: High";
              mail($to,$subject,$message,$headers);
              header("Location: http://www.theiraddress.com/thankyou.html");
              exit;
              }
              ?>

              The mail still went through, but the page did not redirect to thankyou.html.

              Is my syntax correct?

              Thanks

              Dave

              • 4. Re: PHP Form Redirect - Second attempt
                Level 7
                Can you show me your full webpage code, including the PHP code, please?

                Easiest thing is to paste it all into the body of a blank .html page as
                plain text.

                --
                Shane H
                shane@NOSPAMavenuedesigners.com
                http://www.avenuedesigners.com

                =============================================
                Proud GAWDS Member
                http://www.gawds.org/showmember.php?memberid=1495

                Delivering accessible websites to all ...
                =============================================


                "Dave Anderson" <Dave@DaveandHolly.com> wrote in message
                news:e64o5s$t29$1@forums.macromedia.com...
                > Shane H wrote:
                >> Dave -
                >>
                >> You need to add a header to the PHP code. After you validate the contact
                >> page against itself and after the e-mail is sent using the mail$()
                >> command, add a header to redirect to the thankyou.html page -
                >>
                >> It could look something like this:
                >>
                >> mail$(blah,blah,blah,blah)
                >> header("Location: http://www.example.com/thankyou.html");
                >> exit;
                >>
                >
                >
                > Shane,
                >
                > Not sure I follow...
                >
                > The bottom of my PHP code looks like this:
                >
                > $message .= "Phone: " . $_POST['frmphone'] . "\n";
                > $message .= "Comments: " . $_POST['frmcomment'] . "\n";
                > $to = "admin@myurl.com";
                > $subject = "Web Contact Form Inquiry";
                > $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
                > $headers .= "X-Priority: 1 \r \n";
                > $headers .= "X-MSMail-Priority: High";
                > mail($to,$subject,$message,$headers);
                > }
                > ?>
                >
                > Based on what I'm understanding, I changed it to this:
                >
                > $message .= "Phone: " . $_POST['frmphone'] . "\n";
                > $message .= "Comments: " . $_POST['frmcomment'] . "\n";
                > $to = "admin@myurl.com";
                > $subject = "Web Contact Form Inquiry";
                > $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
                > $headers .= "X-Priority: 1 \r \n";
                > $headers .= "X-MSMail-Priority: High";
                > mail($to,$subject,$message,$headers);
                > header("Location: http://www.theiraddress.com/thankyou.html");
                > exit;
                > }
                > ?>
                >
                > The mail still went through, but the page did not redirect to
                > thankyou.html.
                >
                > Is my syntax correct?
                >
                > Thanks
                >
                > Dave
                >


                • 5. Re: PHP Form Redirect - Second attempt
                  Level 7
                  Here it is. I changed the .com stuff a bit.

                  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                  " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                  <html xmlns=" http://www.w3.org/1999/xhtml">

                  <head>
                  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                  <title>Paramount Construction of STNY</title>
                  <link href="../css/layout.css" rel="stylesheet" type="text/css" />

                  <body>
                  <div id="wrapper">
                  <div id="header"></div>
                  <div id="nav">
                  <div id="tabs">
                  <ul>
                  <li><a href="../index.html">About Us</a></li>
                  <li><a href="certification.html">Certifications</a></li>
                  <li><a href="maint.html">Maintenance</a></li>
                  <li><a href="portfolio.html">Portfolio</a></li>
                  <li class="here">Contact Us</li>
                  </ul>
                  </div></div>
                  <div id="content">
                  <div id="image"><IMG SRC="../assets/images/stba_banner.gif" width="100"
                  height="100" STYLE="WIDTH:100px; HEIGHT:100px"><br />
                  <span class="p">Member - Southern Tier<br />Builders
                  Association</span></div>
                  <h1>Do You Have a Question? </h1>

                  <span class="h2">Contact Us </span><br />
                  <span class="p">If you have any questions that we may answer, or
                  if you would
                  like a free estimate for your project, please fill out this
                  form.</span>

                  <p><span class="h2">Our Guarantee to You:</span><br />
                  <span class="p">We promise to provide you with top notch
                  professional and reliable service that you
                  can depend on. In addition, we are proud members of:</span></p>
                  <ul>
                  <li>Southern Tier Builders Association</li>
                  <li>Jamestown Area Chamber of Commerce</li>
                  <li>The Better Business Bureau of Upstate New York</li>
                  </ul>
                  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
                  enctype="multipart/form-data" name="ContactInfo" target="_self"
                  id="ContactInfo">
                  <fieldset>
                  <legend class="h2">Contact Information </legend><br />
                  <span class="reqFieldLabel">** Items in Red indicate required
                  fields</span><br />
                  <label for="name" class="reqField">Name</label> <input type="text"
                  name="frmName" id="textfield" /><br />
                  <label for="company">Company</label> <input name="frmCompany"
                  type="text" id="label" /><br />
                  <label for="address 1">Address 1</label> <input name="frmAddress1"
                  type="text" id="label2" /><br />
                  <label for="address 2">Address 2</label> <input name="frmAddress2"
                  type="text" id="label3" /><br />
                  <label for="city">City</label> <input name="frmCity" type="text"
                  id="label4" /><br />
                  <label for="state">State</label> <input name="frmState" type="text"
                  id="label5" /><br />
                  <label for="zipCode">ZipCode</label> <input name="frmZipCode"
                  type="text" id="txt" /><br />
                  <label for="e-mail" class="reqField">e-mail</label> <input
                  name="frmemail" type="text" id="label7" /><br />
                  <label for="phone" class="reqField">Phone</label> <input
                  name="frmphone" type="text" id="label8" />
                  <br />
                  <br />
                  <p><label for="comments">Comments</label> <textarea
                  name="frmcomment" cols="50" rows="10" id="textfield">This form under
                  construction</textarea>
                  </p>
                  <input name="action" type="hidden" id="action" value="send" />
                  <input type="submit" class="submit" value="Submit" />
                  <?php
                  if($_POST['action'] == "send"){
                  $message = "";
                  $message .= "Hey Mike, Here is some information for you to
                  follow up on from the web site that was posted at " . date("H:i") . " on
                  " . date( "m/d/Y") . "\n\n";
                  $message .= "Name: " . $_POST['frmName'] . "\n";
                  $message .= "Address: " . $_POST['frmAddress1'] . "\n";
                  if(strlen($_POST['frmAddress2']) > 0){
                  $message .= "Address2: " . $_POST['frmAddress2'] . "\n";
                  }
                  $message .= "City: " . $_POST['frmCity'] . "\n";
                  $message .= "State: " . $_POST['frmState'] . "\n";
                  $message .= "ZipCode: " . $_POST['frmZipCode'] . "\n";
                  $message .= "E-Mail: " . $_POST['frmemail'] . "\n";
                  $message .= "Phone: " . $_POST['frmphone'] . "\n";
                  $message .= "Comments: " . $_POST['frmcomment'] . "\n";
                  $to = "dave@dave.com";
                  $subject = "Web Contact Form Inquiry";
                  $headers = "From: Paramount Construction <dave@dave.com>\r \n";
                  $headers .= "X-Priority: 1 \r \n";
                  $headers .= "X-MSMail-Priority: High";
                  mail($to,$subject,$message,$headers);
                  }
                  ?>
                  </fieldset>
                  </form>
                  <div class="h3" ="Address">
                  Paramount Construction<br />
                  1879 Lyndon Blvd<br />
                  NY, NY 14733-0488<br />
                  (716)487-4444<br />
                  (716)487-5555 fax</div>
                  </div>

                  <div id="footer">Copyright 2006 - Paramount Construction, Inc.<br />
                  design by Streetwise Creative</div>
                  </div>
                  </body>
                  </html>

                  • 6. Re: PHP Form Redirect - Second attempt
                    Level 7
                    Shane H wrote:
                    > Can you show me your full webpage code, including the PHP code, please?
                    >
                    > Easiest thing is to paste it all into the body of a blank .html page as
                    > plain text.
                    >


                    or this

                    www.paramount-const.com/index.txt
                    • 7. Re: PHP Form Redirect - Second attempt
                      Level 7
                      $message .= "Phone: " . $_POST['frmphone'] . "\n";
                      $message .= "Comments: " . $_POST['frmcomment'] . "\n";
                      $to = "admin@myurl.com";
                      $subject = "Web Contact Form Inquiry";
                      $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
                      $headers .= "X-Priority: 1 \r \n";
                      $headers .= "X-MSMail-Priority: High";
                      mail($to,$subject,$message,$headers);
                      header("Location: thankyou.php");
                      exit;
                      }
                      ?>

                      Does that work?
                      --

                      kim
                      --------------------------
                      http://geekministry.com
                      • 8. Re: PHP Form Redirect - Second attempt
                        Level 7
                        Kim wrote:
                        > $message .= "Phone: " . $_POST['frmphone'] . "\n";
                        > $message .= "Comments: " . $_POST['frmcomment'] . "\n";
                        > $to = "admin@myurl.com";
                        > $subject = "Web Contact Form Inquiry";
                        > $headers = "From: Paramount Construction <client@theiraddress.com>\r\n";
                        > $headers .= "X-Priority: 1 \r \n";
                        > $headers .= "X-MSMail-Priority: High";
                        > mail($to,$subject,$message,$headers);
                        > header("Location: thankyou.php");
                        > exit;
                        > }
                        > ?>
                        >
                        > Does that work?


                        Hi Kim,

                        Mail goes through, but no redirect... I even created a thankyou.php page
                        instead of the .html I had been using. Still nuttin.

                        I'm doing all of this testing from a temp preview page generated by DW8.
                        That shouldn't matter though, should it?
                        • 9. Re: PHP Form Redirect - Second attempt
                          Level 7
                          On Tue 06 Jun 2006 04:50:38p, Dave Anderson wrote in
                          macromedia.dreamweaver:

                          >> mail($to,$subject,$message,$headers);
                          >> header("Location: thankyou.php");
                          >> exit;
                          >> }
                          >> ?>
                          >>
                          >> Does that work?
                          >
                          > Hi Kim,
                          >
                          > Mail goes through, but no redirect... I even created a thankyou.php
                          > page instead of the .html I had been using. Still nuttin.

                          Ain't gonna happen, because you've already sent content to the browser
                          before you hit the header() function:

                          Remember that header() must be called before any actual output is
                          sent, either by normal HTML tags, blank lines in a file, or from PHP.

                          http://www.php.net/manual/en/function.header.php

                          In fact, I'm surprised that it's not throwing an error.

                          For my 2� worth, your best bet is to make your 'thank you' page the one
                          which processes the form:

                          <form method="PUT" action="thankyou.php">
                          ...

                          and put the PHP code which creates the email in thankyou.php
                          • 10. Re: PHP Form Redirect - Second attempt
                            Level 7
                            Joe Makowiec wrote:
                            > <form method="PUT" action="thankyou.php">

                            That's a new one on me. Surely you mean method="post"?

                            --
                            David Powers
                            Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                            Author, "Foundation PHP 5 for Flash" (friends of ED)
                            http://foundationphp.com/
                            • 11. Re: PHP Form Redirect - Second attempt
                              Level 7
                              On Tue 06 Jun 2006 06:54:27p, David Powers wrote in macromedia.dreamweaver:

                              > Joe Makowiec wrote:
                              >> <form method="PUT" action="thankyou.php">
                              >
                              > That's a new one on me. Surely you mean method="post"?

                              Yup. <sputter />
                              • 12. Re: PHP Form Redirect - Second attempt - SOLVED
                                Level 7
                                Joe Makowiec wrote:
                                > Ain't gonna happen, because you've already sent content to the browser
                                > before you hit the header() function:
                                >
                                > Remember that header() must be called before any actual output is
                                > sent, either by normal HTML tags, blank lines in a file, or from PHP.
                                >
                                > http://www.php.net/manual/en/function.header.php
                                >
                                > In fact, I'm surprised that it's not throwing an error.
                                >
                                > For my 2� worth, your best bet is to make your 'thank you' page the one
                                > which processes the form:
                                >
                                > <form method="PUT" action="thankyou.php">
                                > ...
                                >
                                > and put the PHP code which creates the email in thankyou.php

                                EUREKA! That did the trick, Joe... That's GOLD!!

                                I would have never thought of doing that either. Pretty crafty.

                                Thanks for everyone's help...

                                Now on to finding out how to make several fields required... Not sure if
                                it can be done with pure PHP or if some voodoo Java is in order.

                                Dave
                                • 13. Re: PHP Form Redirect - Here's one for you...
                                  Level 7
                                  Since the Thank You page actually processes the PHP script, is it
                                  theoretically possible to customize the page with the variable that
                                  contains the name field? Just a wonderin.

                                  Thanks

                                  Dave
                                  • 14. Re: PHP Form Redirect - Here's one for you...
                                    Level 7
                                    Dave Anderson wrote:
                                    > Since the Thank You page actually processes the PHP script, is it
                                    > theoretically possible to customize the page with the variable that
                                    > contains the name field? Just a wonderin.

                                    Yes, of course.

                                    echo 'Thank you, '.htmlentities($_POST['name']).'.';

                                    --
                                    David Powers
                                    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
                                    Author, "Foundation PHP 5 for Flash" (friends of ED)
                                    http://foundationphp.com/
                                    • 15. Re: PHP Form Redirect - Here's one for you...
                                      Level 7
                                      David Powers wrote:
                                      > Yes, of course.
                                      >
                                      > echo 'Thank you, '.htmlentities($_POST['name']).'.';
                                      >

                                      Again, awesome! It works well..

                                      Dave
                                      • 16. Re: PHP Form Redirect - Second attempt - SOLVED
                                        Level 7
                                        On 06 Jun 2006 in macromedia.dreamweaver, Dave Anderson wrote:

                                        > Now on to finding out how to make several fields required... Not
                                        > sure if it can be done with pure PHP or if some voodoo Java is in
                                        > order.

                                        If by Java you mean javascript, no; it's not reliable. People (and
                                        specifically spambots) have it turned off.

                                        <?php
                                        if(!isset($_POST['name'])) {
                                        // You didn't include your name ...
                                        // Do something other than mail()
                                        }
                                        ...
                                        // otherwise
                                        mail(...);
                                        }
                                        ?>
                                        --
                                        Joe Makowiec
                                        http://makowiec.net/
                                        Email: http://makowiec.net/email.php