Sorry for my bad title!:) According to this question how can I check and store the appeared field's value With php and mysql;
assume that the form is something like this:
<form method="post" action="#">
<select name="job" id="job" class="medium">
<option selected="selected" value="-1">Please Select...</option>
<option value="1">Job A</option>
<option value="2">Job B</option>
<option value="3">Job C</option>
<option value="4">Job D</option>
<option value="0">Other</option>
</select>
<div id="foo" style="display:none;">
<input type="text" name="job_other" id="job_other" placeholder="If Other, please specify" value="" />
</div>
<div>
<input type="submit" name="submit" id="submit" value="submit" />
</div>
</form>
when selecting the "Other" option, "job_other" text field will appear.(handled by javascript) is my procedure true to check and get field in php like this:
<?php
$input['job'] = (isset($_POST['job']) && $_POST['job'] != '-1') ? $_POST['job'] : '';
if ( $input['job'] != '' && $input['job'] == '0') {
$input['job_other'] = (isset($_POST['job_other']) && $_POST['job_other'] != '' && $_POST['job_other'] == '0') ? $_POST['job_other'] : '';
}
?>
By the way when the field appear, it will be Required. so how can I do this better?
if ( $input['job'] != '' && $input['job'] == '0')could be simplified byif($input['job'] == '0'): demoif($input['job'] === '0')so it doesn't matchfalse,0orFALSE. Demo