readonly for Forms 2.0 | Community
Skip to main content
April 9, 2014
Question

readonly for Forms 2.0

  • April 9, 2014
  • 4 replies
  • 1397 views
Is there any way we can make a specific field read-only? We've tried using jQuery and it doesn't appear to be working (in fact we are having trouble with the selectors working with Forms 2.0). I understand that there is a new API for the forms but I don't see any methods that would allow adjusting form elements attributes (and does the API work on native Marketo LPs?).

Any thoughts or direction would be appreciated.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

4 replies

April 15, 2014
I agree. jQuery seems to be only partially working. I can’t select input fields to make read only, add text to hidden fields or add CSS to them. This is a real problem that Marketo should address. JQuery was pushed as a solution to advanced form design and all of the sudden it’s not available to use in forms 2.0.
April 30, 2014
Hi

Below is an option that has worked for us.

It works using the Forms 2.0 API and JS.

After loading the form a callback function is called that will set the value of a text field then set the it to read only.

In this example it selects the MobilePhone field. But can be applied to any any form fields, by replacing id and value.

<script src="//app-sjo.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1311"></form>

<script>
MktoForms2.loadForm("//app-sjo.marketo.com", "XXX-XXX-XXX", 1311, function(form){
    form.setValues({ "MobilePhone": "999-999-999"});
    document.getElementById('MobilePhone').setAttribute('readonly', 'true');
});
</script>


 
 
May 1, 2014
Is this for an embedded form?
May 1, 2014
Yes.

Add the function 

function(form){
    form.setValues({ "MobilePhone": "999-999-999"});
    document.getElementById('MobilePhone').setAttribute('readonly', 'true');
}

after the formid parameter in the forms 2.0 embed script.