1 Reply Latest reply on Mar 15, 2010 12:35 PM by pziecina

    question regarding php form

    rochellekirk

      Hi everyone and thank you for  reading my question, I have whats hopefully a quick and easy fix: I  followed the instructions on the dreamweaver help site to make a contact  form. Instaed of having it redirected to a conformation page I would  just like it to say "thank you, message sent" below the submit button.  Can you let me know how I can make that possible?

      Here is the  contact.php that i have now

      <!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=utf-8" />
      <title>contact.php</title>
      </head>

       

      <body><?php
      //--------------------------Set  these paramaters--------------------------

       

      // Subject of email sent to  you.
      $subject = 'Questions submitted from website';

       

      // Your  email address. This is where the form information will be sent.
      $emailadd  = 'mail@info@wb-apts.com';

       

      // Where to  redirect after form is processed.
      $url = 'http://www.wb-apts.com/index.html';

       

      // Makes  all fields required. If set to '1' no field can not be empty. If set to  '0' any or all fields can be empty.
      $req = '1';

       

      //  --------------------------Do not edit below this  line--------------------------
      $text = "Results from form:\n\n";
      $space  = ' ';
      $line = '
      ';
      foreach ($_POST as $key => $value)
      {
      if  ($req == '1')
      {
      if ($value == '')
      {echo "$key is empty";die;}
      }
      $j  = strlen($key);
      if ($j >= 20)
      {echo "Name of form element $key  cannot be longer than 20 characters";die;}
      $j = 20 - $j;
      for ($i =  1; $i <= $j; $i++)
      {$space .= ' ';}
      $value = str_replace('\n',  "$line", $value);
      $conc = "{$key}:$space{$value}$line";
      $text .=  $conc;
      $space = ' ';
      }
      mail($emailadd, $subject, $text, 'From:  '.$emailadd.'');
      echo '<META HTTP-EQUIV=Refresh CONTENT="0;  URL='.$url.'">';
      ?>
      </body>
      </html>

       

      Thank you,  thank you, thank you

        • 1. Re: question regarding php form
          pziecina Level 6

          Hi

           

          First please do not post the same question twice, even if they are in different sections of the forum.

           

          In your php file replace -

           

          mail($emailadd, $subject, $text, 'From:  '.$emailadd.'');
          echo  '<META HTTP-EQUIV=Refresh CONTENT="0;  URL='.$url.'">';

           

          with

           

               $success = mail($emailadd, $subject, $text, 'From:  '.$emailadd.'');

              if ($success) {
                $responseText =  "Thank you for your contact/feedback!";
              }
              exit();

           

          Then use javascript to echo the message, (this is jQuery)

          function showResponse(responseText)  {
                   $('.response').text(responseText);
               };

           

          Then in your html include a tag (possibly p tag) with a class of response to display the message.

           

          No error message is shown here but you should include one in the if($success).

           

          PZ

          www.pziecina.com