MktoForms2 :: Hide Fields + Wrappers

by sanford

HTML

<script src="//app-sj01.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_169"></form>
<script>MktoForms2.loadForm("//app-sj01.marketo.com", "410-XOR-673", 169,
function(form) 
{

    //  tag all outer wrapper DIVs with their inner inputs' names to make them usable from CSS
    for ( var formEl = form.getFormElem()[0], formRows = formEl.querySelectorAll('.mktoFormRow'), i = 0, imax = formRows.length, wrappedInput; i < imax; i++ ) 
    {    
        if ( (wrappedInput = formRows[i].querySelector('INPUT')) && wrappedInput.name) 
        {
            formRows[i].setAttribute('data-wrapper-for', wrappedInput.name);
        }
    }
    
    // append the `Company` field to the Thank You URL before redirecting
    form.onSuccess(function(values,thankYouURL) 
    {
        thankYouURL += "&company=" + values.Company;
        window.location = thankYouURL;
        return false;
    })
    
        
});        
</script>

CSS

.mktoFormRow[data-wrapper-for="Email"] {
    /* display: none; */
    outline: 2px dotted red;
}