Paid affiliate advertisement
Form API tweaking - **** Closed ****
kappaluppa - October 13, 2009 - 05:58
I am modifying the email_download module which uses Form API and need help with getting fields to be required. I don't anticipate it to be something huge. I need help ASAP.
(I don't know how to close out this thread.)

kappalupa
Which field you want to add in the email module. is hook_form_alter is not able to adding the field. Please give more description what is your requirement.
I have only 5 fields in this
I have only 5 fields in this form. The email is already being checked for being a valid email address. That one works fine.
I have added the #required element, but that only puts an asterisk next to the field.
I need the other 4 fields to be checked for not being empty.
I added an if statement to the _validate hook.:
if (!isset($form_state['values']['fname'])) {form_set_error('', 'Enter a first name');
}
I get the error whether or not there is content in the field.
That's it! That's all I have to fix! But I've been trying to figure it out for days!
btw, here is the whole thing: http://pastebin.com/m6bba966e
(I've been modifying the email_download module)
any error in this (line
any error in this (line 354):
if(!$file=file_check_upload('file') ) {Did you try to use NULL
Did you try to use NULL instead of '' for the first parameter here
form_set_error('', 'Enter a first name');Solution
There is mixing of code drupal5 and drupal6 .currently you use the drupal5 but you write the code as per drupal6. There is no variable $form_state in form_validate hook in drupal5 . this variable available in drupal6 and onward. use the $form instead $form_state .
So it looks like the problem
So it looks like the problem was that I had the element #value in the form. That must have been causing the element #required to not work. Not sure why. But I've got it fixed now.
Thanks, K