Hi all,

I hope to post in the correct section...
Excuse me in advance for my bad english, I'm french and very tired...

I've recently discovered Drupal and really enjoy this tool, but I don't understand how to modify posted values in the validate function...
I saw "form_set_value()" can modify values which will be transmitted in the submit process,
but in the case of an error appears in validate, these modifications are lost !

How could I do to set new values accessible in the form redisplayed ?

See ya.
Sébastien

Comments

nevets’s picture

I just spent some time this afternoon figuring this out. Declare you validation function with 3 arguments, something like this

function your_form_name_validate($form_id, $form_values, $form) {

then when using drupal_set_value() use $form, something like this

form_set_value($form['some_element_name'], $the_value_you_want_to_set);
webastien’s picture

Thanks for your reply but I've already use "form_set_value".
When the form are redisplayed, "some_element_name" has the old value and not "$the_value_you_want_to_set".
If I force the validate function to be true, "$the_value_you_want_to_set" is take in consideration...
I'll try again in this way if you've got good results with this function.

nevets’s picture

I tried setting a visible field on the form then forced an error and on returning to the edit screen the value did not reflect the call to drupal_set_value().

On the other hand, if there are no errors and I set a value the submit function sees the value set.

webastien’s picture

Exactly, you explain better than me the problem ;)
I search a way some hours, I hope someone could explain us if there is a solution.