dimanche 24 septembre 2017

assign a condition to contact form checkbox to show optional text in email

I am creating a contact form that contains a section with 3 checkboxes. The 3rd checkbox has a 'Month' and 'Year' text field next to it.

`When would you like to start? *
<input type="checkbox" name="when" value="ASAP" /> As soon as possible
<input type="checkbox" name="when" value="Unknown" /> Not sure yet
<input type="checkbox" name="when"  value="Date" /> 
<input placeholder="Month" type="text" name="month" /> <input 
placeholder="Year" type="text" name="year" />`

If the 3rd checkbox is selected then a month and year should be added into the text fields.

in the php file for the form the input for this section is checked and will bring up a warning message if no box is selected.

$when = check_input($_POST['when'], "Please specify when you would like to start");

When the contact form is submitted, the resulting email will show the answer if the 1st or 2nd box are checked, but will only display the value "Date" of the 3rd box, even if the month and year have been entered in the text fields AND those are listed in the php file to be posted in the email.

When would you like to start? $when $month $year

I've tried various ways to add a condition for the 3rd checkbox to the php file where the month and year field would post in the email if the 3rd checkbox is selected, but can't seem to find the correct syntax. Something like this

if (isset(['when']value==Date), $when) 
{
When would you like to start? ($_POST 'month', 'year');
}

but each of the dozens of variations I tried gave me some kind of syntax error. Any help with correcting the conditional syntax, or suggestions on how to get the month and year in those text fields to post to the form's email would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire