PDA

View Full Version : selected option


desrosj
12-03-2006, 03:55 PM
Hey Everyone,
On my site there is a php page where people can enter a message to the person who I run it for. I am adding a selection box in my form. The trick here though that I am unsure how to do is that I want his email to be selected by default. UNLESS they click a link to email me the webmaster, in that case I want mine to be selected. Is there something I can pass in the link? Is there any way to do this without using serverside scripting?
Thanks,
Desrosj

Marlo
12-03-2006, 04:14 PM
OK im going to assume you know at least a little bit about PHP and forms.

So in your form do somthing like this

<form method="post" action="endform.php">
Field 1: <br />
<input type="text" name="field1" /><br />
Field 2: <br />
<input type="text" name="field2" /><br />
Send to owner: <input type="radio" name="whoemail" value="owner" /><br />
Send to webmaster: <input type="radio" name="whoemail" value="webmaster" />
</form>


the main part being the radio option. This will give the option whether to send to the website owner or the Webmaster.

now for the bit that processes the email just add


<?PHP
$owner = 'owner@website.com'; //owners email
$webmaster = 'webmaster@website.com'; //webmasters email
$field1 = $_POST['field1']; //email subject or whatever else
$field2 = $_POST['field2']; //email message or whatever else. you can add more fields.
$option = $_POST['whomail']; //radio button for user to select who to email to.

if($option == 'owner'){
mail ($owner, $field1, $field2); //this will be the email to the owner
}
else
{
mail ($webmaster, $field1, $field2); //this will email to the webmaster
}
?>


This will see which radio button is selected and send the email to which one they selected.