i trying to creating html form where field is displayed on select option value
<form id="myForm">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName"><br><br>
<label for="phoneNumber">Phone Number:</label>
<input type="tel" id="phoneNumber" name="phoneNumber"><br><br>
<label for="email">Email Address:</label>
<input type="email" id="email" name="email"><br><br>
<label for="selectOption">Select Option:</label>
<select id="selectOption" name="selectOption">
<option value="">select for ruin</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select><br><br>
<div id="conditionalFields">
<div id="universityField" style="display: none;">
<label for="university">University:</label>
<input type="text" id="university" name="university"><br><br>
</div>
<div id="textareaField" style="display: none;">
<label for="textarea">Textarea:</label>
<textarea id="textarea" name="textarea"></textarea><br><br>
</div>
<div id="selectField" style="display: none;">
<label for="selectOption2">Select Option 2:</label>
<select id="selectOption2" name="selectOption2">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select><br><br>
</div>
<div id="callField" style="display: none;">
<label for="callme">callme:</label>
<input type="text" id="callme" name="callme"><br><br>
</div>
<div id="addressField" style="display: none;">
<label for="address">Address:</label>
<input type="text" id="address" name="address"><br><br>
</div>
<div id="selectOption3Field" style="display: none;">
<label for="selectOption3">Select Option 3:</label>
<select id="selectOption3" name="selectOption3">
<option value="A1">A1</option>
<option value="B1">B1</option>
<option value="C1">C1</option>
</select><br><br>
</div>
<div id="callmeField" style="display: none;">
<label for="callme">Call Me:</label>
<input type="text" id="callme" name="callme"><br><br>
</div>
</div>
<input type="submit" value="Submit">
</form>
When select with id = “selectOption” option value = “1” is selected Field with id =“universityField” is shown, option value = “2” is selected Field with id=“textareaField” is shown, option value = “3” selected Field with id=“selectOption2” is shown.
I was wondering how could i send only the activate field in mail, let say when option value = “1” is selected i want to send id=“universityField” field value, if option value = “2” is selected i want to send id=“textareaField” field value only
I use follwing code to send mail to client:
$name = $university = $phone;
if (isset($_POST['submit'])) {
$fm_name = $_POST['firstName'];
$fm_university = $_POST['university'];
$fm_phoneNumber = $_POST['phoneNumber'];
$name = quote_input($fm_name);
$university = quote_input($fm_university);
$phone = quote_input($fm_phoneNumber);
if (empty($fm_name)) {
$quoteErr = "Name is Required.";
}
elseif (empty($fm_university)) {
$quoteErr = "university is Required.";
}
elseif (empty($fm_phoneNumber)) {
$quoteErr = "Phone No. is Required.";
}
else{
$headers = 'From: <owner mail >' . "\r\n";
$headers .= "Name : " . $name . "\r\n";
$headers .= "university : ". $university . "\r\n";
$headers .= "Phone : ". $phone . "\r\n";
$mailto = "sendmemail@gmail.com";
$sub = "Get in touch with us";
mail($mailto,$sub,$headers);
$quotesuccess = "Your message has been sent! We will contact you shortly.";
echo $headers;
}
}
function quote_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
so i want to send mail with above code with activate field only, how can i do that