hey there,

I noticed there's no 'reset' button that I can add to my webforms. I don't miss it - in fact I think the easiest way to reset a form is simply to navigate out of it ;]

but clients... they think otherwise.

could we add a reset button on a future version?

regards,
Luciano

Comments

quicksketch’s picture

I personally despise reset buttons. If a particular client is requesting it, I'd suggest that you use a custom module and use hook_form_alter() to add a reset button to all webform forms.

luco’s picture

yeah, I really don't see the point either. but like I said....... clients do. u know, the web isn't always as we wish.

anyway I was looking for something more newbie friendly. or perhaps you could point me to an article that explains further?

traviscarden’s picture

Granted we may not see a compelling reason to use such and such a feature of HTML, but insofar as it exists--and in this case is a common form element, and Webform is meant to simplify the creation of forms--it looks like an oversight to omit it. But suppose a person were filling out a form and decided that they wanted not to leave the form but merely to start over. A page refresh would be superfluous to that end. A reset button would be the most logical solution. Besides, as Luciano points out, sometimes "the client just wants one". And who wants to tell their client, "I'm sorry, a 'Reset' button is complicated functionality in Drupal. I'd have to bill you a couple extra hours to learn to write a custom module to programmatically add one (and then you won't be able to change it through the web interface)"? All that to say that I too would like the ability to add a "reset" button. But, lest I seem to harshly critical, I would like to say that Webform is a great module, and I really appreciate all the work that's gone into making it so useful--even if I have a little different perspective on this particular, little issue. :) Thanks.

quicksketch’s picture

I'm still against this enough that I don't think a single checkbox for "Include a Reset Button" is worth including in the UI, when 99% of people will never want the option (though they might turn on the option even when they don't want or understand it). Adding a reset button through a form alter is not a complicated task.

function mymodule_form_alter($form_id, &$form) {
  if (strpos($form_id, 'webform_client_form_') === 0) {
    $form['reset'] = array(
      '#value' => '<input class="form-button" type="reset" value="Reset" />',
      '#weight' => 1001,
    );
  }
}

Interestingly, Drupal in general has found a reset button so useless that the FAPI doesn't even have a built-in #type for it. Hence why you have to just print the straight HTML.

dave the brave’s picture

You can add a reset button pretty simply by adding a Markup field with <input class="form-button" type="reset" value="Reset" />.

It works just fine, and if you need it positioned after the submit button, just use css to position.

quicksketch’s picture

Status: Active » Closed (won't fix)

As I've said above, there are no plans to implement this in Webform.

kotnik’s picture

Drupal 6 version of this hook is:

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if (strpos($form_id, 'webform_client_form_') === 0) {
    $form['reset'] = array(
       '#value' => '<input class="form-button" type="reset" value="'.t("Reset").'" />',
       '#weight' => 1001,
    );
  }
}
Lucience’s picture

Thank you Dave!

gopisundar’s picture

Version: 7.x-3.15 » 5.x-2.1.2
Status: Closed (works as designed) » Closed (won't fix)

<?php

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

if (strpos($form_id, 'webform_client_form_') === 0 || ($form_id=='user_register_form')) {

$form['actions']['reset'] = array(
'#type' => 'button',
'#value' => t('Reset'),
'#weight' => 100,
'#validate' => array(),
'#attributes' => array('onclick' => 'this.form.reset(); return false;'),
);
}
}
this works for drupal 7..

luco’s picture

Status: Closed (won't fix) » Active

@quicksketch, I've reopened this issue just to ask you: if someone were to write a patch for Webform that included a reset button component, would you be willing to integrate it into your module?

regards

luco’s picture

Version: 5.x-2.1.2 » 7.x-3.15
quicksketch’s picture

@quicksketch, I've reopened this issue just to ask you: if someone were to write a patch for Webform that included a reset button component, would you be willing to integrate it into your module?

No probably not. Though if you want to make it a component, you can easily keep that in a separate module by using Webform's hook_webform_component_info().

luco’s picture

Status: Active » Closed (works as designed)

it just hit me! there is a simpler way to go about this.

simply add a markup field with <input type="reset" value="Reset" id="reset-button"> at the end, then style it. ta-daaa! ;)

gopisundar’s picture

Version: 5.x-2.1.2 » 7.x-3.15
Status: Closed (won't fix) » Closed (works as designed)

@luco
By doing this you can bring the reset button in webform but you cant arrange the button with submit button. the code i posted will do that too.

luco’s picture

@gopisundar sure! my solution is heavier on CSS, but lighter on PHP. that's all. ;)

gopisundar’s picture

@luco
Ya thats right. i gave a suggestion:)

technikh’s picture

#9 Worked like a charm. Thanks gopisundar!

thetpaing’s picture

Thanks gopisundar ......

谢艳’s picture

Currently, i am using the way provide from #5, it works like a charm.haha

rreiss’s picture

Issue summary: View changes

#13 Is the best (and easiest) answer in my opinion.

rcodina’s picture

+1 to solution explained in #13. Thanks!!!

jabastin arul’s picture

You can add a reset button pretty simply by adding a Markup field with .
But its not an best pratice. My suggestion is you may alter the form like this...

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