1

I have enabled Profile 2 and profile Profile2 Registration Path modules on my site and have a really long registration form with lots of fields. I have some radio boxes and file upload fields also. The problem is when I upload a file without having selected a valid option for my mandatory radio box. IF the radio box is empty when I hit upload, the file gets uploaded and I get the error "illegal option, contact admin". After that the error keeps repeating if I try to remove the file.

In my reports I see

Location http://localhost:6600/sitename/el/file/ajax/profile_customer/field_cv/und/0/form-Q8VxLye65S3tYFkcHSwO9Z58dG7Mhv6jRWRBnIst46s

Referrer http://localhost:6600/sitename/el/customer/register

Message Illegal choice in Specialty element.

The Specialty element is my radio box. If I enter an option in the radio box before uploading the document everything works as it should! Removing the file is troublefree also. I am completely baffled with this. I’ve searched and found many issues with file upload and radio boxes values connected to ajax. Seems weird that this thing isn't working. Can't be the only one with files and radio boxes in his registration form! Any ideas/pointers on how to solve this irritating issue?

1 Answer 1

0

If I understand you right you'll need to write a small custom module to hook into the registration form using hook_form_alter(), and add the #limit_validation_errors property to the correct radio group. This should stop the validation from running on AJAX calls, but still let it run when the form is submitted.

The code might look something like this:

function MYMODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  $form['radio_button']['#limit_validation_errors'] = array();
}

It's quite likely that the particular radio group you're after will be buried in the nested $form array somewhere so you'll probably need to use the dpm() function (part of of the Devel module) to inspect the form and determine the correct element to alter.

4
  • This is going to require a lot of research from my part since I am unfamilliar with the form api. If you know any good tutorials/examples with hook_form_alter please point me to them.
    – Perisdr
    Commented Mar 30, 2012 at 18:06
  • This one looks pretty good, also see the Form API docs, it's a big page but have a look at the comments at the bottom as they contain some good code examples. Google is also your friend here. Good luck :)
    – Clive
    Commented Mar 30, 2012 at 18:10
  • Oh, there's also the Examples module which has tons of code examples for the Drupal API. It's a great resource, I'd probably start there to be honest. When you come across something you just can't grasp/work out just post another question on here and I'm sure someone will be able to help you out
    – Clive
    Commented Mar 30, 2012 at 18:14
  • Thanks Clive, I' ll start reading and hopefully it won't be that complicated.
    – Perisdr
    Commented Mar 31, 2012 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.