If i use the following for definition of radios field: 0:NO;1:YES and set the field to required.

when i view the survey i have the NO case pre-selected.. which is odd; but acceptable.. but if i submit with this case, it fails validation.

unfortunate i guess that the survey module couldnt use cck as its form builder as it is much more supported, tested and feature rich.. but i guess overkill for surveys??? but maybe could use a subset of their fields??

Comments

liquidcms’s picture

ok, i think i have the solution.. but not sure why the code was written like this???

the forms module validates fields on its own.. like radio buttons.. but the code that is used, specifically this:

function forms_validate($form, $edit) {
  $error = false;
  
  foreach ($form->fields as $field) {
    if ($field->required && (!$edit[$field->name] || $edit[$field->name] === false)) {
      form_set_error($field->name, t('%field is required', array('%field' => '<em>'.$field->title.'</em>')));
      $error = true;
    }

is wrong!!

Radio buttons can have a valid selection of "0".

The part that is more odd though is that this function exists at all.. the forms module is using (as it should) the forms api; which already does the checks... and it does them correctly... you can see the code runs through both.. it first does the std forms api check.. which passes in my example (as it should) but then runs the forms module check (which is coded wrong and which fails)... but i simply commented out the form_set_error and error = true lines above and things seem to work correctly now... i.e. if i have radios that dont get a default (which for incorrectly is anytime i dont have a value of 0 as an option) and i submit.. the form fails (from std forms api check).. and if i submit a value of 0.. it passes; as it should.

quicksketch’s picture

Status: Active » Closed (fixed)

Forms and survey modules are no longer being maintained, use Webform module instead.

---Closing down issue queue of survey module---