PHP Error After Submitting a Form: Reset Button Not Working

Asked By 0 points N/A Posted on -
qa-featured

Hello,

I am currently building a site that will be functioning the same as PHPmyAdmin.Hopefully. But that's too far to finish.

To everybody here who knows how to retain a value into the form, actually it was pretty easy. But talking about clearing after retaining values for me is super confusing. I got stuck on reset button that doesn't function anymore after the form has been submitted. It was perfect before I click “submit” button. I just don’t understand why HTML reset does not have the power to remove PHP values. 

I've got a search bar that enables the administrator to search by id and last name. I want the reset to still function after submit button is clicked. What would be the best and simple short code for this problem? Is there a new technique on this such as using JQUERY or AJAX?

Thank you.

Jonel_J

SHARE
Answered By 0 points N/A #94029

PHP Error After Submitting a Form: Reset Button Not Working

qa-featured

Hi Jonel.

HTML reset button doesn't work after submission because it loads value back to form first load (which is after submission, not before). So you may try to create a jQuery function to clear form. This is an example :

$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

Then call this function on button click (assuming you have form with id 'form1' and button with id 'btnClear') :

$('#btnClear').click(function(){
  $('#form1').clearForm();
});

Check attached file for complete code example. Hope it helps.

Related Questions