473,385 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP email form values

stepterr
157 100+
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
5 2170
Lumpy
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
stepterr
157 100+
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
  1.  
  2. <?php 
  3.   $flag=1;  
  4.   //form validation is done everytime this page loads .If a check fails the $flag gets set to 0.
  5.  
  6. ?>
  7.  
  8. //Begin HTML
  9. //create table, etc.
  10.  
  11.  
  12. <form name="form2" method="post" <?php if ($flag == "0") {?>action="formtest.php"<?php }else{?>action="email.php">
  13.          <?php }?>>
  14.  
  15.   if ($flag == "0") {    
  16.   //This will display any error messages as well as the fields so they can make the corrections needed
  17.   ?>
  18.  
  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">
  31.  
  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>
  42.  
  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>
  47.  
  48.  
*** 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
  2.  
  3. $to = "myemail@email.com";
  4. $from = "myemail@email.com";
  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. ?>
  13.  
Nov 18 '07 #3
ak1dnar
1,584 Expert 1GB
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
Lumpy
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
  1.  
  2. <input type="hidden" name="ConfirmedCampanyName" value=" <?php echo $_POST['coCampanyName']; ?>">
  3.  
  4.  
and then in your email processing call for the post variable ConfirmedCompanyName instead of the coCompanyName.

Hope this helps!
Nov 18 '07 #5
stepterr
157 100+
Thanks Lumpy, that worked perfectly!
Nov 18 '07 #6

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

Similar topics

10
by: Dave Karmens | last post by:
If I have say 10 fixed variables, how can I set their values = to that of a form that is built dynamically? column1 column2 email = formvalue(0) fname = formvalue(1) lname = formvalue(2)...
1
by: TJS | last post by:
after I allow users to modify form values with javascript the form values are no longer are available on the action page. how can I allow the user to modfy form values via javascript and still...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
3
by: Miguel Dias Moura | last post by:
Hello, i created an ASP.net / VB page with a really big form. Now i want to create 4 pages and in each one i will place 1/4 of the big form. The last page will send all the form values by...
3
by: desh | last post by:
hello How to retain the values in form tag ,in case user enter wrong information.
9
by: Steve Poe | last post by:
Configuration: PHP 4.3.9 Apache 2.0.52 Hello PHP group, I am a novice to PHP. I have searched through the newsgroup on my issue but I am not sure I know what I am missing.
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
3
by: copleyuk | last post by:
I have created a form and am emailing it via php. If I use plain text I can get all the entered information to email correctly. However, I wanted to have the information from the form laid out in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.