2

I have one form with some fields with submit and reset button. I am using cakephp model validation to validate empty and special characters. If I enter invalid data and submit the form, its displaying error message.After that I click on reset button,its not reset the form. Before validation error message its working fine.

My reset button code is

<input type="reset" class="uiBtn" value="Reset" name="reset">&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="uiBtn" value="Save Section" name="">

Also I used jquery reset function, its also not working..

Please any one help me what is the problem???

1 Answer 1

1

It doesn't work because HTML Reset buttons reset the controls in a form back to the value they were when the page first loaded. When you post back, the PHP engine sets the values of the controls again, so the Reset would do nothing more than change the controls back to what they were when you loaded the page after the postback.

The only solution to this is to either do it client-side with javascript or server-side on a postback. Just iterate through all of your controls and set their properties appropriately.

Following Js Code would certainly work, assuming you don't have another onload event already set.

window.onload = function () {
for(var f in document.getElementsByTagName("form"))
    f.reset();
}

This post might help you to reset the form after submit.

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.