Jump to content

Reset validation status after script execution


Recommended Posts

I have started playing around with jQuery mainly to allow me to create complicated forms without clicking through several php pages collecting all the data.


It's is probably not relevant but I will give the full picture of what i am attempting feel free to ignore this paragraph if it is of no use!
I have a table of MySQL rows with checkboxes. There will be 3 different options for bulk processing of the checked rows and on clicking one of the options a hidden div will fade in and the options buttons will disappear (to prevent several options divs being opened at the same same). In the div there will be form elements relevant to the bulk processing option chosen. For the first one it is simply one text input. Upon Submit it will validate that the input is not empty and if so, execute the function that posts the data. The data gets posted, the div gets replaced and a success message is displayed, plus the bulk option buttons return ready to choose another option. This new div gets hidden once a bulk option next gets clicked. This all works correctly but there is an issue with clearing the validation.


So the problem I actually have is that after successful validation and script execution the data is still in memory so if I run through the process again with an empty field, you see the validation error message again, briefly, but the script still runs. Is there any way to clear everything still in memory at the end of script execution? I have tried a few suggestions I have seen and a few things I have tried as a complete guess-up but no joy....


I am sure that there must be a way to do this but I am completely stumped. If anyone can offer any suggestions I would be grateful. Also, although this code is something I am just playing around with and will not be used on a production site, if there is anything in the scripts that could be done better, feel free to say. but don't be too harsh!!


Thanks in advance


The Validation part

    //Validate Defaults
     debug: true,
     success: "valid"
    //Validate Rules
	  var validator = $('#bulkMatchActions').validate({
		rules: {
			required: true
		messages: {
		  ppReason: "Please enter a reason"

	  //On Submit, run the posting script

                  //After the above script is run, I want everything set to NOT VALID ready to validate an empty field again

		  return false;
	 //Empty the form

The actual posting script

function postponeSubmit(){
  $('#postponeSubmit').click(function() {
	var ppSubmit = 'ppSubmit';
	var ppReason = $('#ppReason').val();
	var checkBox = $.map($('input:checkbox:checked'), function(e,i) {
	  return +e.value;
	var checkBox2 = $('#checkbox');
	$('#postpone2 p').text('Loading....');
	$.post('inc/processForm.php', { ppReason : ppReason, ppSubmit : ppSubmit, checkBox : checkBox }, function(data){
	$('#postpone2 p').html(data);
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.