I have a field in the contact form that can contain 2 results, and I would like to send whatever was filled in, I believe that because I use the same name so I do not need to use two "Orders" fields. I believe I have to do a validation.

Example Pseudo code:

if { 
orders = 1 
send orders
} else { 
orders = null
send orders2

Backend Email Template

<p><strong>Order: </strong> {{var data.order}}<br></p>


<div id="pedido" name="pedido" style="display:none;">
        <label for="pedido" class="required"><em>*</em>Pedido</label>
        <div class="input-box">
            <select style="height:25px; padding:3px; display: none;" name="order" id="orders"></select>
        <div class="input-box">
        <input style="width:262px; display: none;" name="order" id="ordertxt" class="input-box required-entry" type="text" />

The input is sent normally, only the select is not, I believe that it is because the input is set to value 1, and when it is not filled the code sends null, so I think a validation should be done, that is possible? Would anyone know how to do it? I thank you!

1 Answer 1


You could simply remove the element via javascript before submit based on this validation.


document.getElementById("form").onsubmit = function() {
    if(document.getElementById("orders").value == "")
    if(document.getElementById("ordertxt").value == "")

So it checks the form with ID of form for when it is submitted and then checks values in the fields orders or ordertxt, if a value is empty the element is removed before form submission. This will allow for you to only send data from a field if it was filled out.

  • ha no worries Gustavo
    – harri
    Commented Aug 12, 2017 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.