modifying form html | Community
Skip to main content
July 31, 2014
Solved

modifying form html

  • July 31, 2014
  • 3 replies
  • 1265 views

Is there a way to actually modify the html of the forms that are created?  For example lets say I wanted to add an Id or change the class name or add a new attribute altogether.

Thanks,
 

Dan

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Kenny_Elkington
Hey Daniel,

You cannot do this from directly within the form editor, but you can do this with the addition of some custom code.  Since Forms 2 loads asynchronously you'll need to use the whenReady event to make sure that the code executes correctly:

<script>
MktoForms2.whenReady(function(form){
$('#yourId').addClass('myClass myOtherClass'); //add a class
$('#yourId').attr('yourAttribute', 'yourValue'); //add an attribute with a value
});
</script>

Keep in mind that you can only have a single id per element, so overwriting this is not a good id, and can break form functionality.

3 replies

July 31, 2014

Thanks for that!  That worked.

Dan

Kenny_Elkington
Kenny_ElkingtonAccepted solution
New Participant
July 31, 2014
Hey Daniel,

You cannot do this from directly within the form editor, but you can do this with the addition of some custom code.  Since Forms 2 loads asynchronously you'll need to use the whenReady event to make sure that the code executes correctly:

<script>
MktoForms2.whenReady(function(form){
$('#yourId').addClass('myClass myOtherClass'); //add a class
$('#yourId').attr('yourAttribute', 'yourValue'); //add an attribute with a value
});
</script>

Keep in mind that you can only have a single id per element, so overwriting this is not a good id, and can break form functionality.
Dory_Viscoglio
New Participant
July 31, 2014
Hi Dan, I believe that you can do this on the page where your form resides. It isn't done directly in the form.