PDA

View Full Version : emailing webform with form results


vavi2sal
05-02-2011, 12:58 AM
Hello,

I have a 2 part form that I am trying to get to gather data and send to an email I designate I am having trouble on the simplest part which is sending all data from both forms to an email address. I appreciate any help.



step1.php


<form action="step2.php" method="post">
<p>
Loan Type:
<select name="loanType">
<option>Loan Type 1</option>
<option>Loan Type 2</option>
<option>Loan Type 3</option>
</select>
</p>
<p>
Property Type:
<select name="peopertyType">
<option>Property Type 1</option>
<option>Property Type 2</option>
<option>Property Type 3</option>
</select>
</p>
<p>
Property State:
<select name="peopertyState">
<option>Property State 1</option>
<option>Property State 2</option>
<option>Property State 3</option>
</select>
</p>
<p><input type="submit" name="step1_submit" value="Continue &rarr;" /></p>
</form>


step2.php


<?php
session_start();
if(isset($_POST['step1_submit']))
{
$_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */
?>
<form action="step3.php" method="post">
<p>
Credit Score:
<select name="creditScore">
<option>500 - 600</option>
<option>600 - 700</option>
<option>800 - 900</option>
</select>
</p>
<p>
Phone Number: <input type="text" name="phoneNumber" />
</p>
<p>
Email Address: <input type="text" name="emailAddress" />
</p>
<p><input type="submit" name="step2_submit" value="Continue &rarr;" /></p>
</form>
<?php
}
else
{
?>
Please fill in <a href="step1.php">Step 1</a>
<?php
};
?>


step3.php


<?php
session_start();
if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
{
echo "Your data: <h1>Step 1</h1>";
foreach($_SESSION['step1_data'] as $field => $value)
{
if($field != 'step1_submit')
echo "<p><b>$field</b> = $value</p>";
}
echo "<h1>Step 2</h1>";
foreach($_POST as $field => $value)
{
if($field != 'step2_submit')
echo "<p><b>$field</b> = $value</p>";
}
}
else
{
echo 'Fill in <a href="step1.php">Step 1</a>';
}
?>

edbr
05-02-2011, 02:13 AM
so what is the problem exactly? have to echoed out the data to see if it is being passed?

vavi2sal
05-02-2011, 04:24 AM
never was a problem, at the beginning of the code i asked how to send the form results to an email

edbr
05-02-2011, 04:59 AM
mail() if you know about sessions i didnt think you would not know this, there is a mail script in tutorials

vavi2sal
05-02-2011, 05:14 AM
thanks anyway i was looking for help with this form because ive been there and tried that, the results shoot back only the first page not the second page of results. I didnt think this help forum was to help people by directing them elsewhere.

edbr
05-02-2011, 05:19 AM
this is why i asked what problems you are having.
the results shoot back only the first page not the second page of results.]
does this mean you are not passing the data or what. and for your information directing you to a mail script6 is not sending you somewhere else. so be clear about what you need , and you may get help

vavi2sal
05-02-2011, 05:29 AM
did you try the code? the data passes fine, but i was looking for help on sending the results from all pages - which is on step3 - to an email

edbr
05-02-2011, 05:38 AM
noi didnt test your cose i asked you to echo the results but you didnt answer.
Make a variable of the data and call it for example, $message, then mail it

example
mail($recipient,$email,$message, $from th mail form i told you about is a tutorial so that should help you

vavi2sal
05-02-2011, 07:47 AM
uggh so confusing, i tried that too and didnt work as you can probly see im new to php programming and this is the last step to my form but its not sending all the data from step3.php its only getting data from step2 i tried some code from a tutorial and it didnt work either ill post below

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

// Subject of email sent to you.
$subject = 'Results from Contact form';

// Your email address. This is where the form information will be sent.
$emailadd = 'mail@rdsnetworks.net';

// Where to redirect after form is processed.
$url = 'http://www.rdsnetworks.net/confirmation.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 = '0';

// --------------------------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.'">';
?>

edbr
05-02-2011, 08:33 AM
ok hold on

edbr
05-03-2011, 03:51 AM
try this
step2.php


<?php
session_start();




if(isset($_POST['step1_submit']))
{
$_SESSION['step1_data'] = $_POST; /* add all data from step1 to session variable */
echo $_POST['loanType'];

?>
<form action="step3.php" method="post">
<p>
Credit Score:
<select name="creditScore">
<option>500 - 600</option>
<option>600 - 700</option>
<option>800 - 900</option>
</select>
</p>
<p>
Phone Number: <input type="text" name="phoneNumber" />
</p>
<p>
Email Address: <input type="text" name="emailAddress" />
</p>

<input type="hidden" name="peopertyType" value=" <?php echo $_POST['peopertyType'] ; ?>" />
<input type="hidden" name="loanType" value=" <?php echo $_POST['loanType'] ; ?>" />
<input type="hidden" name="peopertyState" value=" <?php echo $_POST['peopertyState'] ; ?>" />



<p><input type="submit" name="step2_submit" value="Continue &rarr;" /></p>
</form>
<?php
}
else
{
?>
Please fill in <a href="step1.php">Step 1</a>
<?php
};
?>

and step 3
session_start();

//Edit the below
$to = "email@email.com";
$from = "email@email.com";
$subject = "Subject";

//Do not edit
$peopertyState = $_POST['peopertyState'];
$peopertyType=$_POST['peopertyType'] ;
$loanType= $_POST['loanType'];
$emailAddress= $_POST['emailAddress'];
$phoneNumber= $_POST['phoneNumber'];


$message = "
$peopertyState \n
$loanType\n
$peopertyType \n
$emailAddress \n
$phoneNumber\n
";



if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
{
echo "Your data: <h1>Step 1</h1>";
foreach($_SESSION['step1_data'] as $field => $value)
{
if($field != 'step1_submit')
echo "<p><b>$field</b> = $value</p>";
}
echo "<h1>Step 2</h1>";
foreach($_POST as $field => $value)
{
if($field != 'step2_submit')
echo "<p><b>$field</b> = $value</p>";

mail($to, $subject, $message, 'From: '.$from.'');


}
}
else
{
echo 'Fill in <a href="step1.php">Step 1</a>';
}

vavi2sal
05-03-2011, 06:18 PM
oh i didnt realize the message rolled over onto a second page. I tried the above and it sends four emails simultaneously and only echoes the following results: email, phone and loan type

edbr
05-04-2011, 12:30 AM
dumb i put it in the wrong place sorry . ill re write and test before posting it back

edbr
05-04-2011, 03:40 AM
i dont have time to test mail but echoed out the message so should be gold now.

If you are just getting those few results i suspect you dint update page 2 , just a guess

step 3
<?php
session_start();

//Edit the below
$to = "email@email.com";
$from = "email@email.com";
$subject = "Subject";

//Do not edit
$peopertyState = $_POST['peopertyState'];
$peopertyType=$_POST['peopertyType'] ;
$loanType= $_POST['loanType'];
$emailAddress= $_POST['emailAddress'];
$phoneNumber= $_POST['phoneNumber'];
$creditScore = $_POST['creditScore'];

$message = "
Property State: $peopertyState \n
Loan Type : $loanType\n
Property type: $peopertyType \n
Credit Score : $creditScore \n
Email Address : $emailAddress \n
Phone Number : $phoneNumber\n
";



if(isset($_POST['step2_submit']) && isset($_SESSION['step1_data']))
{
echo "Your data: <h1>Step 1</h1>";
foreach($_SESSION['step1_data'] as $field => $value)
{
if($field != 'step1_submit')
echo "<p><b>$field</b> = $value</p>";
}
echo "<h1>Step 2</h1>";
foreach($_POST as $field => $value)
{
if($field != 'step2_submit')
echo "<p><b>$field</b> = $value</p>";




}


}


else
{
echo 'Fill in <a href="step1.php">Step 1</a>';
}
if($emailAddress !=" "){



mail($to, $subject, $message, 'From: '.$emailadd.'');
}
?>

vavi2sal
05-04-2011, 04:47 AM
IT WORKED!! you have no idea how long I have been trying to get this done. I truly appreciate the time you spent on it. now i just need to make the tweaks to use it on the site. thanks so much again!!

edbr
05-04-2011, 05:03 AM
you were being thrown by the way the forms validated. I cheated by putting the values of step 1 into hidden fields in step 2 that by passed the validation and could nbe all collected a s post variables, and you are welcome, see we do help when asked the right questions :)