Reset button on the form

0

I want to reset all fields of a form using CakePHP framework.

What happens is the following, the register button is only enabled if the user checks the box to accept.

If he clicks the clean button, I want you to leave the text-type fields empty and also reset radio and checkbox .

The way I'm doing it only works to reset the text type, but I want to reset all types of form fields. Let's go part of it.

echo $this->Form->create('users');

echo $this->Form->input('name', array('label'=>'login'));

echo $this->Form->input('password', array('label'=>'senha'));

//checkbox para abilitar o cadastro

echo $this->Form->input('aceitar', array('label'=>'aceito realizar cadastro', 'name'=>'aceitar', 'onclick'=>'cadastrar.disabled!=checked'));

//botao cadastrar

echo $this->Form->submit('cadastrar', array('label'=>'Cadastrar', 'name'=>'cadastrar', 'onclick'=>'disabled=true'));

//reset

//da forma abaixo só desabilita o botão cadastrar e o checkbox continua marcado.

echo $this->Form->button('limpar', array('label'=>'limpar', 'onclick'=>'cadastrar.disabled=true'));

//ou desmarca o checkbox e o botão fica disponível.

echo $this->Form->button('limpar', array('label'=>'limpar', 'onclick'=>'aceitar.checked=false'));

The two forms above do not apply to me.

I want to uncheck checkbox and disable the register button, I already tried to use two onclick on the reset button, but it did not work.

    
asked by anonymous 21.09.2015 / 16:58

3 answers

2

You can use a function in javascript to clear fields

$(function(){
    $('#aceitar').on('click', function(){
       $('#enviar').prop('disabled', !$(this).is(':checked'));
    });

    $('#limpar').on('click', function(){
       $('#aceitar').prop('checked', false); 
       $('#enviar').prop('disabled', true);
       $('#nome').val(''); 

    });
});

Example: jsfiddle

    
21.09.2015 / 17:07
1

You can use pure JavaScript to solve your problem by being very simple.

Example:

document.getElementById("myForm").reset();
    
21.09.2015 / 19:09
0

You can add an input of type reset , it will reset the form to its default values, eg:

Form:

 <form name="myform" method="POST">
  <input type="text" size="25" value="">
  <input type="text" size="25" value="Valor default">
  <input type="checkbox">
  <input type="radio">
  <input type="submit" value="enviar"> 
  <input type="reset" value="Resetar!">

</form>
    
21.09.2015 / 18:57