I am trying to inject a CSS class into the form output where the class pulls from the value of a hidden form field. Yes, I know that the form has a css field already but that is used for styles.
I have targeted a form with an ID of 48 and added a custom function to add the form title in the output as “form name”. That part is working well but I am trying to target a hidden field within the form and populate that into my variable: $form_class = $form[‘hiddenfieldvaluehere’];
Hi Dean. Does the hidden field in the form have a default value, and that is what you are trying to pull and use in the form tag when the form renders?
Also, what are you trying to do with the form with that custom class once you have it?
I should also mention that I was able to target the hidden field and populate the default value into the form output. But it did not support the embed url variable.
$form_post = $form['fields'][6]->defaultValue;
I had the default value of the hidden field using a merge tag so it output as:
For this, normally the post ID is part of the body tag, and you could do something like:
body.page-id-133 .gform_wrapper form as your selector for CSS or jQuery.
If your end goal is to ultimately add the post title as a class (I think that a post name with a space in it will foil your plans, because <form class="Contact Us" is not going to be valid) you could grab the post title from the post, in your code, like this:
If you let us know what you need this information about the page for (i.e. “what happens next”) we may be able to help you with alternative methods. Thank you.