PHP email form values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stepterr
    New Member
    • Nov 2007
    • 157

    PHP email form values

    Hi Everyone,
    I'm new to PHP and have been working on an existing from that had been in Coldfusion but needed to be converted to PHP. I have most of it working except I ran into a problem when trying to email the form, the values are showing up blank. I believe it has to do with the flow and how the last step before the email process doesn't actually have the values in input fields, rather just displays the information with in html tags using $_POST['fieldname'] . The page goes like this:
    1.) formtest.php : They fill in the form, hit submit.
    2.) The page submits to itself (formtest.php) and it goes through and validates the inputs.
    3.) If any of the validation fail it displays the form with the error message so that they can correct it and resubmit.
    4.) If the form has been filled out correctly then the form fields are hidden and we display what they filled out in order for them to confirm. Or they have the option to return to form and correct anything that they want changed.

    I was hoping that since both the form and the confirmation were within the same <form> tag that when the confirmation was submitted (using the post method) that it would pass the information along to our email.php page and send the email with the values.

    If I skip the confirmation and just submit the form and send it to email.php the values will fill in but we really need to have that confirmation first. Any help on this would be greatly appreciated! thanks!
  • Lumpy
    New Member
    • Oct 2007
    • 69

    #2
    Without seeing the code form both pages, the form page and the email page, it is tough to say why the post variables are not being emailed to you.

    Reading through your post, I did wonder if upon confirmation and final submittal to the email page if the email page is looking for the right post variables. But that is really only a guess without seeing the code for both the pages you are using.

    Comment

    • stepterr
      New Member
      • Nov 2007
      • 157

      #3
      Here is the basics of it. Its a very large form so I've only listed one of the fields that we use so that you don't have to look through all of that

      ** This is the testform.php page
      [code=php]

      <?php
      $flag=1;
      //form validation is done everytime this page loads .If a check fails the $flag gets set to 0.

      ?>

      //Begin HTML
      //create table, etc.


      <form name="form2" method="post" <?php if ($flag == "0") {?>action="form test.php"<?php }else{?>action= "email.php" >
      <?php }?>>

      if ($flag == "0") {
      //This will display any error messages as well as the fields so they can make the corrections needed
      ?>

      <table width="580" border="0" cellspacing="1" >
      <tr>
      <td colspan="3">
      <p align="center">
      <b><font face="Arial" size="2">Compan y Contact Information</font></b></td>
      </tr>
      <tr>
      <td width="239"><p class="mainbody "><font color="#336699" ><b>Company Name:</b> (required)</font><br>
      <input name="coCompany Name" value="<?php echo $_POST['coCompanyName']?>" size=30 maxlength=100 tabindex="1"></font></td>
      </tr>
      </table>
      <input type="submit" value="Submit" name="Submit">

      <?php }
      else{
      // This is the confirmation that just displays the information to the user
      ?>
      <table>
      <tr>
      <td ><p class="mainbody "><font color="#336699" ><b>Company Name: </b>
      <?php echo $_POST['coCompanyName']?></font></td>
      </tr>
      </table>

      <input type="submit" value="Confirm" name="Confirm">
      <input type="submit" value="Return to Form" onClick="goback ();" name="Return"></p>
      <?php }?>
      </form>

      [/code]
      *** this is what is on the email.php page. Again, I've only left the one field on this so its not so long.
      [code=php]
      <?php

      $to = "myemail@email. com";
      $from = "myemail@email. com";
      $subject = "Company Contact Information";
      $message = "A company has submitted its profile.Here is the company contact information:" . "\n\n";
      $message .="Company Name:"."\n";
      $message .= $_POST['coCompanyName'];
      $headers = "From: $from\r\n";
      $headers .= "Content-type: text/html\r\n";
      $mail = mail($to, $subject, $message, $headers);
      ?>
      [/code]
      Last edited by ak1dnar; Nov 18 '07, 02:56 AM. Reason: Fixed missing CODE Tags

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Are you sure, is this the same code structure as original? Can't you post the entire Page here.
        NOTE: Please use the [CODE=php] while posting source codes.

        Comment

        • Lumpy
          New Member
          • Oct 2007
          • 69

          #5
          Thank you for posting some code, it makes it easier to see what the possible problems could be.

          First thing I saw is on line 11 you have an extra ">" after, action="email.p hp">. You don't need that because you will be closing the form tag off after the php is complete.

          The second thing I saw, and maybe I am just missing it, is if the form passes and goes to the confirmation part, there is no hidden post variables in which to send to the email page. You might want to add in something like....

          [CODE=php]

          <input type="hidden" name="Confirmed CampanyName" value=" <?php echo $_POST['coCampanyName']; ?>">

          [/CODE]

          and then in your email processing call for the post variable ConfirmedCompan yName instead of the coCompanyName.

          Hope this helps!

          Comment

          • stepterr
            New Member
            • Nov 2007
            • 157

            #6
            Thanks Lumpy, that worked perfectly!

            Comment

            Working...