By takinola on
I want to perform custom validation on a form by using Javascript code to capture the onsubmit action of the form. I have tried using the following code (as suggested by http://drupal.org/node/725882) to set the onsubmit attribute of the form to the appropriate Javascript function but it never gets called.
$form['#attributes']['onsubmit'] = ' return func()';
I have inspected my form using
<?php
print "<pre>";
print_r($form);
print "</pre>";
?>
and I noticed the [#attributes] does not have any values in it so I suspect the code to set the onsubmit function is not taking.
Any pointers as to the right course of action would be much appreciated.
Thanks
Comments
What type of validation are
What type of validation are you trying to do?
You can do a lot of validation with js...
I am trying to check if the
I am trying to check if the user has modified the default text in the input area and prompt the user to enter new data if not
jQuery(function() { var
Thanks! Where does this go?
Thanks! Where does this go? In the nodetype-edit.tpl.php or in the actual html page header?
You can put it in either.
You can put it in either. Just need to make sure the ids match up with your form.
I still can't get it to
I still can't get it to work.
I used node-nodetype_edit.tpl.php to set the Id of my form to 'myform' and the id of the text input to 'myforminfield' but nothing happens when the form is submitted.
I am very new to JQuery so there may be some basic step I am missing. Could you please explain in some detail what to do to get this code working?
Thanks
I wasn't suggesting modifying
I wasn't suggesting modifying the ids of the fields - use webdev toolbar - or view source and get the existing ids of those items and modify the js snippet.
don't forget to wrap the jQ in script tags
Thanks for the patience but
Thanks for the help. Your code, with appropriate modifications, worked to solve the problem. In the interest of anyone else reading this exchange, there is a typo in the 3rd line in the original. The code should read
I inserted this code in my script.js and was good to go