I have a simple php mail form that echos user input after submission and also mails input information to specified email address. One of the fields is age. Is there a way to echo a set of numbers (insurance quote rates)based on the user's input of age? For example, if user inputs an age range from 18-24, $150/month would display on page after submission, if the user inputs an age range from 25-31, $175/month would display on the page after submission.
This is my form page code:
<HTML>
<HEAD>
<TITLE>E-Mail Form</TITLE></HEAD>
<BODY>
<FORM action="sendmail.php" method="POST">
<p><strong>Name:</strong>
<INPUT type="text" size="25" name="name"></p>
<p><strong>Age:</strong>
<INPUT type="text" size="3" name="age"><b>
<select name="sex" id="sex">
<option value="female">female</option>
<option value="male">male</option>
</select>
</b></p>
<p><strong>Children:</strong>
<INPUT type="text" size="3" name="children">
</p>
<p><strong>E-Mail Address:</strong>
<INPUT type="text" size="25" name="email"></p>
<p><strong>Message:</strong><br>
<textarea name="message" cols=30 rows=5></textarea></p>
<p><INPUT type="submit" value="send"></p>
</FORM>
</BODY>
</HTML>
This is my php processing code:
<html>
<head>
<title>Health Insurance Rates</title>
</head>
<body>
<?php
//page display after form submission
echo "<p>Thank you, <b>$_POST[name]</b>, for your message!</p>";
echo "<p>Your e-mail address is: <b>$_POST[email]</b>.</p>";
echo "<p>Your message was:<br>";
echo "$_POST[message] </p>";
//start building the mail string
$msg = "Name: $_POST[name]\n";
$msg .= "Age: $_POST[age]\n";
$msg .= "Sex: $_POST[sex]\n";
$msg .= "Children: $_POST[children]\n";
$msg .= "E-Mail: $_POST[email]\n";
$msg .= "Message: $_POST[message]\n";
//set up the mail
$recipient = "info@ringartdesign.com";
$subject = "Health Insurance Quote";
$mailheaders = "From: 2 Step Health <info@2stephealth.com> \n";
$mailheaders .= "Reply-To: $_POST[email]";
//send the mail
mail($recipient, $subject, $msg, $mailheaders);
?>
</body>
</html>
PHP Form echo set of numbers based on input
Moderator: General Moderators
-
ringartdesign
- Forum Newbie
- Posts: 21
- Joined: Wed Sep 10, 2008 10:11 am
Re: PHP Form echo set of numbers based on input
You would just do this by using if tests on the upper/lower bounds you require. You can do this in the same code or as a seperate function and call it.
Code: Select all
if (($_POST['age'] >= 18) && ($_POST['age'] <= 24))
$quote=150;
elseif (($_POST['age'] >= 25) && ($_POST['age'] <= 31))
$quote=175;
echo "Quote: $".$quote."/m";
Last edited by Dravos on Wed Sep 10, 2008 10:57 am, edited 1 time in total.
-
ringartdesign
- Forum Newbie
- Posts: 21
- Joined: Wed Sep 10, 2008 10:11 am
Re: PHP Form echo set of numbers based on input
Great, that works...thank you!
Is there a way to add $25/m for each child entered into the "children" field?
Also, can I send an auto response with the same echoed info to the person who filled out the form?
Is there a way to add $25/m for each child entered into the "children" field?
Also, can I send an auto response with the same echoed info to the person who filled out the form?
Re: PHP Form echo set of numbers based on input
Well the children part, you can add to the quote you already have from age, just append this line after the if statements:
The autoupdate thing could probably be done with javascript/ajax, but I'm not too fluent with that.
Code: Select all
$quote+=($_POST['children']*25);