is there a way to hack so the first Selection Option is empty and force user to select....I have searched for a while and cant get any solution other than using content profile which I really don't need

I would really appreciate some feedback.
Thanks

Comments

flug’s picture

I'm wondering about this, too. This is very common in drop-down box selections--it starts out blank & the user must actually select a value before proceeding, not just accept the given value.

flug’s picture

This thread has a bit more about it: http://drupal.org/node/41846

The problem was that 'required field' was coming in with "--" as the initial selection, and then accepting that as the response if the user didn't change that initial selection.

So they got working it over in that thread and decided, well it's not OK to allow "--" as the response, so we'll just **remove it** from the list of responses if a response is required.

Problem is, that if you are requiring a response you want users to actually MAKE A RESPONSE, not just lazily accept the first/default response whether that is "--" or something else.

In my case the best solution for now seems to be to uncheck 'response required' for this field. If people don't make a choice I'd rather at least know that!

And in the long run they need to add the "--" option back in but if the user accepts that option that counts as **no response** and they are kicked back to the form to give a response.

flug’s picture

Here is the snippet of code that will fix the problem.

You also need to know that you can now enter "--" as the first entry and leaving that entry selected is considered a non-answer.

In the file 'profile.module' (which will be in your modules directory under 'profile', find the "profile_validate_profile" function and replace it with this:


function profile_validate_profile($edit, $category) {
  $result = _profile_get_fields($category);
  while ($field = db_fetch_object($result)) {
    if ($edit[$field->name]) {
      if ($field->type == 'url') {
        if (!valid_url($edit[$field->name], TRUE)) {
          form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => $field->title)));
        }
      } elseif ($field->type == 'selection') {
        if ($edit[$field->name] == "--" ) {
          form_set_error($field->name, t('You must select one of the options in the %field field.', array('%field' => $field->title)));
        } 
      }  
    }
    else if ($field->required && !user_access('administer users')) {
      form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title)));
    }
  }

  return $edit;
}
srfloppy’s picture

I work with laste release of drupal 6.17. The last snippet not works for me and I've found that at line 395 of 'profile.module' the code says:

394:      case 'selection':
395:        $options = $field->required ? array() : array('--');

is this ok? Seems that this code, if the field is required, try to append an array with the '--' value, but then I think that it would be:

395:        $options = $field->required ? array('--') : array();

not? I've changed the line but the snippet not working for any of the two ways.

Debugging the code, i've seen too that the the code into the while snippet never runs, seems that have a problem with the fields in a category.