0

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>

Phtml

<div id="pedido" name="pedido" style="display:none;">
    <li>
        <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>
    </li>    
    <li>
        <div class="input-box">
        <input style="width:262px; display: none;" name="order" id="ordertxt" class="input-box required-entry" type="text" />
        </div>
    </li>
</div>  

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!

2

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

e.g.

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

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 Aug 12 '17 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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