2

I use webform with multistep for a quiz. I want to add a "skip" button (equivalent to the submit/next button in the bottom of the form) above the form so that people can go directly to the next question without having to scroll down the page like that :

" Skip this question

My form

< Previous | Next >"

I succeeded to add an another submit button (check code below). But when I click on this button it returns to the previous step instead of going to the next step ... I don't understand why .. And I can not put it above the form.

function mytemplate_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
  case 'webform_client_form_13':
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('skip'),
    );
    break;
  }
}

Have you got an idea for help me ?

Thanks you for advance

PS : sorry for my bad english

4
  • Why do you want that? If your fields are not required, simply clicking next would do the same what skip does, right? So what's the problem? And if fields are required, what would you want to happen later, when your code expects them, but data is simply missing?
    – Mołot
    Commented Nov 20, 2014 at 7:55
  • I try to add a skip button on the top because my form is very long and people have to scroll to get to the next button. If they do not want to answer a question based on skip it up without having to go down.
    – Pierre
    Commented Nov 20, 2014 at 8:49
  • So, basically, you want a copy of "next", but with different title and placed on top?
    – Mołot
    Commented Nov 20, 2014 at 8:51
  • Yes It's exactly that.
    – Pierre
    Commented Nov 20, 2014 at 9:04

2 Answers 2

2

It seems that basically, you want a copy of "next", but with different title and placed on top. To achieve it:

  1. Examine structure of form you are alerting. Find where original "next" is defined.

  2. Create a copy of it. Use code like:

    $form['my_skip_button'] = $form['path']['to']['next']['button'];
    

    You Don't really need to know or care what it is, you need a copy, so you go and make a copy, simple as that.

  3. Set weight to something low to get it to top:

    $form['my_skip_button']['#weight'] = -10;
    
  4. You can alter the title in the same way you altered weight.

0

Please also think about ability to hide/show field depending on user's selection. It's called 'Conditionals'. For example, user selects his role ('speaker') and some fields could be hidden and some new shown.

If all fields in this step are hidden (even required fields) this step will be skipped.

More details:

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.