By numfar85 on
I have a form with a textarea. When you click submit a function 'mymodule_form_submit()' is called and within that a function that checks the content of the textarea called 'mymodule_check_before_submit()' is called to make sure that the content that the user will try to add follows certain guidelines. If it does not the content of the textarea should remain and an error message is given to the user who is given a chance to correct their mistake.
I have gotten the error message to appear but the textarea gets cleared. How can I fix this so that the content of the textarea stays?
Comments
Initilized a session variable
by using hook_form_alter() you can initialized a session variable to store textarea value at validation time.
and use this session variable as a default value of textarea.
You should use #element_validate
Hi,
You should do a textarea value validation.
in the form build function:
And you make a function:
When I go through the
When I go through the textarea text I create an error array that contain all the possible different problems with the text, when calling form_error() can I iterate over the array? Right now I do this to show the error messages:
I tried doing something like this but it didn't work:
and
The function _molmeth_check_before_submit() returns a(possibly empty) error array.
The error message I get
The error message I get say:
"Warning: Invalid argument supplied for foreach() in _form_validate() (line 1378 of /var/www/sity/drupal-7.12/includes/form.inc)."
'#element_validate' =>
'#element_validate' => array('_molmeth_textarea_validate')#element_validate is an array of function names, so that other modules can use hook_form_alter to add their own validation to the list without over-writing what comes before.
ah, yes, changing this makes
ah, yes, changing this makes it work. But I can't get it to show more then one error message. Can form_error() only be used to give one error message or should it be possible to loop over it giving it a bunch of different error messages or should that be done in a different way?
Hi, I have gone through your
Hi,
I have gone through your query and thought of giving you a solution. May be it can help you.
For validating the the text area content, you can use hook_validate() function and put the validation whatever you want.
For rendering the content after click submit. you can provide this code before your form element.
I hope, it will help you.