Hi
I wanted to add the novalidate attribute to my <form> element to stop the HTML5 validation. Some find it a bit ugly and would prefer to validate with javascript.
I used the JQuery .attr to do that like this:
$("#my_form_id.attr( "novalidate",true );
Easy. But I wanted to do this without using javascript in case the user had it disabled in their browser.
I was able to do that with the user_meta_form_display hook and a php string replace like this:
add_filter('user_meta_form_display', 'add_novalidate',10,3);
function add_novalidate( $html, $formName, $formData ) {
if ($formName == 'my_form_name' {
$html = str_replace( '<form, '<form novalidate="true"', $html );
return $html;
}
}
Better ideas and comments welcome. I hope there isn’t a button I could have pushed somewhere to do this. 🙂
Couldn’t get the edit function to work.
The code in the previous post for adding the novalidate attribute is a mess of syntax errors…sorry.
Here’s a better version.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the ...
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.