This feels like it might be a lot of work to fix, but currently mandatory fields block the usage of the "previous page" button for paged forms. I'm guessing that each page is validating every time the user hits Next or Previous? The browser's Back button seems to work (at least on Firefox), but this is still likely to confuse people.

Having the form validate only at submit time might be a pain to implement, in the case where there are invalid fields on more than one page... But maybe a compromise would be to only validate on Next, and not on Previous - since the user will have to Next his way through all pages before submitting anyway.

Anyway, for now I'm going back to a one-page form.

Comments

quicksketch’s picture

Yes, unfortunately this is a very difficult problem to fix. Drupal performs the mandatory field validation separate from everything else, and Webform doesn't get a chance to tell Drupal not to validate required fields. To make this work, Webform would need to individually theme every form element to give it the required "*" on output next to the label, but not actually make the field required. Then do a separate validation check to validate required fields. :P

The whole thing is quite ugly, I think it's something we might need to deal with until it's easier to override in Drupal core.

gvdvenis’s picture

Status: Active » Postponed
willeaton’s picture

Status: Postponed » Active

Have you tried the form API...
'#executes_submit_callback' => 'FALSE',
for button fields? If nothing else you can try and just make this a javascript back button using "drupal_add_js()" and make the "return" false. That way you can do an onclick= history(-1). If someone doesnt have javascript enabled then they are just faced with the same problem and nothing is broken.

I hope that helps in solving it quicker, it is quite annoying :-)

Thanks
Will

quicksketch’s picture

If the submit callback is not submitted, then any values the user has submitted on that page are not saved. This would basically be replacing an existing problem with a different one.

platypus media’s picture

Version: 5.x-2.0 » 6.x-2.6

This is also a problem in D6

dldege’s picture

I have a work around that might be able to be worked in to a real patch for this issue.

In my additional form validation I added

 if ($form_state['values']['op'] == '< Previous Page') {
   form_set_error(NULL, '', TRUE);  // reset form errors
   drupal_get_messages('error', TRUE); //clear error messages
 }

the idea is simple - on the back button I unset all the form_errors rather then trying to find a way to bypass validation.

mbaizman’s picture

This is a great workaround. Verified.

quicksketch’s picture

Status: Active » Closed (duplicate)
miro_dietiker’s picture

Can you please add this as a patch for the module?
Would be great...

eloiguell’s picture

#6 dldege-->It works for Drupal 6. In Drupal 5 I have fixed it this way:

1.-In my additional form validation I added

<?php
if ($form_values['op'] == '< Previous Page') {   
   form_set_error(NULL, '', TRUE);  // reset form errors
   drupal_get_messages('error', TRUE); //clear error messages   
}
?>

2.- Change the form_set_error function:

<?php
/**
 * File an error against a form element. If the name of the element is
 * edit[foo][bar] then you may pass either foo or foo][bar as $name
 * foo will set an error for all its children.
 * AQUESTA FUNCIO ES LA ORIGINAL DE LA VERSIO DRUPAL 5, 
 * SUBSTITUIM PER LA DE DRUPAL 6 PER A RESOLDRE BUG
 * WEBFORM I PREVIOUS PAGE AMB REQUIRED FIELDS.
 
function form_set_error($name = NULL, $message = '') {
  static $form = array();
  if (isset($name) && !isset($form[$name])) {
    $form[$name] = $message;
    if ($message) {
      drupal_set_message($message, 'error');
    }
  }
  return $form;
}
*/

function form_set_error($name = NULL, $message = '', $reset = FALSE) {
  static $form = array();
  if ($reset) {
    $form = array();
  }
  if (isset($name) && !isset($form[$name])) {
    $form[$name] = $message;
    if ($message) {
      drupal_set_message($message, 'error');
    }
  }
  return $form;
}

?>

Thanks dldege!!

hendrakieran’s picture

hendrakieran’s picture

@ #6: Is there anywhere within the module that reset this values (after your code unset them)? My concern is that the values remain unset for the remaining of the form. In my test, clicking on the "Next Page >" button (after I clicked the Previous button) on a mandatory component is possible without entering anything. So this may have overwrites the mandatory rule on that component.