jeudi 24 août 2017

PHP won't echo HTML with Checkbox Array Results

I am stumped!!! I'm get the results beautifully, but I cannot get the associated text to show up "ONLY" when something is selected by the user. As it is now, the text is static and shows ALL the time, with or without a selected answer from the user.

Ex. "What Kind of Animal:" Is on the results page, even if the user does not select an answer for it! That's what needs to not show if there's no related answer.

My HTML:

    <!-- SHOW/HIDE TEXT FIELD -->
    <!-- IF BITTEN ANIMAL="YES" or BITTEN "BOTH" Show Field -->
<div id="hidden_textfield10" style="display:none;">
    <p class="data_bold">What Kind of Animal</p><div class="data_small">What kind of animal has your pet bitten? Check all that apply:</div>
    <label for="Wild"><input class="form_style" type="checkbox" value="Wild" id="Wild" name="whatKindofAnimal[5]" />Wild</label><br />
    <label for="Bird"><input class="form_style" type="checkbox" value="Bird" id="Bird" name="whatKindofAnimal[4]" />Bird</label><br />
    <label for="Cat"><input class="form_style" type="checkbox" value="Cat" id="Cat" name="whatKindofAnimal[3]" />Cat</label><br />
    <label for="Dog"><input class="form_style" type="checkbox" value="Dog" id="Dog" name="whatKindofAnimal[2]" />Dog</label><br />
    <label for="Other-Animal"><input class="form_style" type="checkbox" id="Other-Animal" name="whatKindofAnimal[1]" onclick="if(!this.checked) document.getElementById('otherKindofAnimal').value='' " />Other</label>
    <!-- IF BITTEN ANIMAL="Other" Show Field -->
<div class="Other-Animal" style="display:none;">
    <input class="form_style" type="text" placeholder="Please Specify" id="otherKindofAnimal" name="whatKindofAnimal[1]" />
</div>
    <!-- END "Other" Field -->

PHP:

        <p class="data_answers">
    <?php if (isset($_POST['whatKindofAnimal'])) {echo '<strong>What Kind of Animal:</strong> '; $name = $whatKindofAnimal = implode(', ', array_filter($_POST['whatKindofAnimal'])); echo htmlspecialchars($whatKindofAnimal);} ?>

I have been using the first part of this PHP code for the radio buttons throughout my whole page and it works perfectly! This is how I have it set elsewhere for radio buttons... and the associated text only shows up when the user as actually selected an answer.

  <p class="data_answers">
    <?php if (isset($_POST['bite-reported-human'])) {echo '<strong>Bite Reported:</strong> '; echo htmlspecialchars($_POST['bite-reported-human']);} ?></p>

In this case, "Bite Reported:" Remains invisible on results page unless an answer has been selected for it.

Please help????

Thank You in Advance, Tracy




Aucun commentaire:

Enregistrer un commentaire