0
I want to reset all fields of a form using Cakephp framework.
What happens is the following, the sign up button is only enabled if the user marks the checkbox to accept.
If he clicks the clear button, I want him to leave the fields of type empty text and also reset the radio
and checkbox
.
The way I’m doing it only works to reset the type text, but I want to reset all kinds of fields in the form. Let’s go to 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 correspond to me.
I want to cancel the checkbox
and disable the sign-up button, already tried using two onclick
on reset button, but did not work.
I do this, but using framework. You did what I do, but in html. It didn’t clear up my question!
– André Nascimento
The code does exactly what you want, but in the proper way, the difference and it does not use javascript as the answer you marked as correct, its justification is not valid.
– David Schrammel
@Andrénascimento I understand that David’s answer does not satisfy you, but the problem is that in the title and the question you only ask to reset the form and David answered exactly this, but when reading your code I see that it goes beyond resetting, you want to reset and disable in certain circumstances, however you did not describe this in the question and of course most could not understand the objective, I recommend that when you ask a question follow the tips: http://answall.com/help/how-to-Ask and http://answall.com/help/mcve ...
– Guilherme Nascimento
@Maybe if you had used at least the tag
javascript
in the question David and the others could have deduced this, but since you did not, I think it wrong to criticize David’s answer, it is perfectly appropriate to what is described, so always try to be the clearest to avoid invalid answers. A good night! I hope you take all this as constructive tips :)– Guilherme Nascimento
@Davidschrammel +1 for his effort, as the answer at the moment answers what is described in the question.
– Guilherme Nascimento