Validation of Radio Button that includes Text Box
Ok. I have a brief form that has a variety of radio buttons and text boxes. Validating text boxes and checkboxes aren't a problem. My problem is validating radio buttons that have an 'Other:' option that includes a textbox.
For example, I have this:
<label for="hearDog">2. How did you hear about this particular dog(s)?</label> <?php if (isset($error['hearDog'])) { ?>
<span class="warning"><?php echo $error['hearDog']; ?></span>
<?php } ?>
<br /><input name="hearDog" type="radio" id="Petfinder.org" value="Petfinder.org" <?php
if (!$_POST || (isset($error) && $_POST['hearDog'] == 'Petfinder.org')) { echo
'checked="checked"';
} ?> />
<label for="Petfinder.org">Petfinder.org</label><input name="hearDog" type="radio" value="Pets911" id="Pets911" <?php
<input name="hearDog" type="radio" value="Other" id="Other" <?php
if (isset($error) && $_POST['hearDog'] == 'Pets911') { echo
'checked="checked"';
} ?> />
<label for="Pets911">Pets911</label>if (!$_POST || (isset($error) && $_POST['hearDog'] == 'Other')) { echo
'checked="checked"';
} ?> />
<label for="Other">Other, please explain:</label>
<br />
<textarea name="hearDog" cols="50" rows="7"><?php if (isset($_POST['hearDog'])) {echo $_POST['hearDog'];} ?></textarea>
The radio button validation I currently have is this:
$hearDog = $_POST['hearDog'];
if (empty($hearDog)) {
$error['hearDog'] = 'Please select how you heard about this dog(s)';
}
My problem is that if someone ops to choose 'Other', but doesn't fill in the textarea, how do I validate the text area and pop the message 'Please select...'. Plus, how do I create create a 'Sticky Radio Button'? I haven't had any luck doing that during my tests.
Thank you for your time.
