Search code examples
phpformscontact-formcode-duplication

Contactform with two date-choices. Only one is showing


Hi there I'm building a form where people have to submit two dates. All in the form seems to be going well but when I fill in the form, and select two dates and hit "send", the automated reply only gives the feedback for one of the dates. I'm not sure my PHP-code knows the form has TWO date options. For some reason one is overwriting the other when the form is send.

I'm not sure which part of the code to copy here. But the problem is basically that I have two date sections. Both show up as HTML/PHP markup. But once selected and submitted - the feedback email only shows one of the dates selected in the form.

Anyone know how I can tell the PHP file that both dates selected need to be fed back?

<div class="row">
    <div class="label">Datum</div><!--  end .label -->
    <div class="input">
        <input type="date" class="detail" name="date">
    </div><!--  end input -->
    <div class="context">Kies een voorkeur datum</div><!--  end .context-->
</div><!-- end .row -->
<div class="row">
    <div class="label">Datum</div><!--  end .label -->
    <div class="input">
        <input type="date" class="detail" name="date">
    </div><!--  end input -->
    <div class="context">Kies tweede een voorkeur datum</div><!--  end .context-->
</div><!-- end .row -->
<div class="row">
    <div class="label">Your message.</div><!--  end .label -->
    <div class="input">
        <textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea>
        <?php if(in_array('comment', $validation)): ?>
            <span class="error"><?php echo $error_messages['comment']; ?></span>
        <?php endif; ?>
    </div><!--  end input -->
</div><!-- end .row -->

Solution

  • Because you are using the same name="date" for both the elements. Replace with the correct one.

    <div class="row">
                <div class="label">Datum</div><!--  end .label -->
                <div class="input">
                    <input type="date" class="detail" name="date1">
    
                </div><!--  end input -->
                <div class="context">Kies een voorkeur datum</div><!--  end .context-->
        </div> <!-- end .row -->
    
            <div class="row">
                <div class="label">Datum</div><!--  end .label -->
                <div class="input">
                    <input type="date" class="detail" name="date2">
    
                </div><!--  end input -->
                <div class="context">Kies tweede een voorkeur datum</div><!--  end .context-->
        </div> <!-- end .row -->
    
    
        <div class="row">
                <div class="label">Your message.</div><!--  end .label -->
                <div class="input">
                <textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?>
    </textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>
    
                </div><!--  end input -->
        </div> <!-- end .row -->