By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,919 Members | 1,690 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,919 IT Pros & Developers. It's quick & easy.

PHP email form values

P: 157
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!
Nov 18 '07 #1
Share this Question
Share on Google+
5 Replies

P: 69
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.
Nov 18 '07 #2

P: 157
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
Expand|Select|Wrap|Line Numbers
  2. <?php 
  3.   $flag=1;  
  4.   //form validation is done everytime this page loads .If a check fails the $flag gets set to 0.
  6. ?>
  8. //Begin HTML
  9. //create table, etc.
  12. <form name="form2" method="post" <?php if ($flag == "0") {?>action="formtest.php"<?php }else{?>action="email.php">
  13.          <?php }?>>
  15.   if ($flag == "0") {    
  16.   //This will display any error messages as well as the fields so they can make the corrections needed
  17.   ?>
  19.       <table width="580"  border="0" cellspacing="1">                
  20.       <tr>
  21.              <td colspan="3">
  22.              <p align="center">
  23.               <b><font face="Arial" size="2">Company Contact Information</font></b></td>
  24.         </tr>
  25.          <tr>
  26.              <td width="239"><p class="mainbody"><font color="#336699"><b>Company Name:</b> (required)</font><br>
  27.                <input name="coCompanyName" value="<?php echo $_POST['coCompanyName']?>" size=30 maxlength=100 tabindex="1"></font></td>
  28.           </tr>
  29.           </table>
  30.          <input type="submit" value="Submit" name="Submit">
  32.    <?php }
  33.    else{
  34.    // This is the confirmation that just displays the information to the user 
  35.    ?>
  36.     <table>
  37.     <tr>
  38.         <td ><p class="mainbody"><font color="#336699"><b>Company Name: </b> 
  39.              <?php echo $_POST['coCompanyName']?></font></td>
  40.          </tr>
  41.          </table>
  43.           <input type="submit" value="Confirm" name="Confirm">
  44.           <input type="submit" value="Return to Form" onClick="goback();" name="Return"></p>
  45.   <?php }?>     
  46. </form>
*** this is what is on the email.php page. Again, I've only left the one field on this so its not so long.
Expand|Select|Wrap|Line Numbers
  1. <?php
  3. $to = "";
  4. $from = "";
  5. $subject = "Company Contact Information";
  6. $message = "A company has submitted its profile.Here is the company contact information:" . "\n\n";
  7. $message .="Company Name:"."\n";
  8. $message .= $_POST['coCompanyName'];
  9. $headers  = "From: $from\r\n";
  10. $headers .= "Content-type: text/html\r\n";
  11. $mail = mail($to, $subject, $message, $headers);
  12. ?>
Nov 18 '07 #3

Expert 100+
P: 1,584
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.
Nov 18 '07 #4

P: 69
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.php">. 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....

Expand|Select|Wrap|Line Numbers
  2. <input type="hidden" name="ConfirmedCampanyName" value=" <?php echo $_POST['coCampanyName']; ?>">
and then in your email processing call for the post variable ConfirmedCompanyName instead of the coCompanyName.

Hope this helps!
Nov 18 '07 #5

P: 157
Thanks Lumpy, that worked perfectly!
Nov 18 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.