1

Reset button is not working after previewing the webform. Means when we click on preview button on webform, then on edit button of webform and then if we click on reset button. it does not work at all. What could be the reason, kindly suggest any solution? My code is as follows :

 function mymodule_form_alter(&$form, &$form_state, $form_id) {

  switch ($form_id) {

    case 'webform_client_form_XYZ':
        $form['submitted']['reset'] = array(
            '#type' => 'button',
            '#value' => t('Reset'),
            '#weight' => 100,
            '#validate' => array(),
            '#attributes' => array('onclick' => 'this.form.reset(); return false;'),
        );
   }
1

Your code works as designed - resets form to a state it was at page load. After preview state JavaScript resets to is set to what user entered. That's not a Drupal issue, that's just how JavaScript and browsers works. Browser simply does not have that data any more - HTTP is a stateless protocol even if we work around it every day and don't even consciously notice that we do.

If you want that button to do something else, you need to use Drupal's AJAX and obtain values you want to reset to from the server directly. Alternatively, you can attach custom submit handler to that button, one that would not really submit anything, but clear data from $form_state['input'] and trigger form reappearing.

0

This code work for all webforms in drupal 7:

<?php

function form_reset_form_alter(&$form, $form_state, $form_id)
{

if (strpos($form_id, 'webform_client_form_') === 0) {
 $form['actions']['reset'] = array(
  '#type' => 'button',
  '#value' => t('Reset'),
  '#weight' => 100,
  '#validate' => array(),
  '#attributes' => array('onclick' => 'this.form.reset(); return false;'),
  );
 }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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