What I would like to do is have 2 buttons to submit a single form. One button is to save the form for editing later the other is to process it.

With...

$("#saveform_ns").click(function(){
$('form#form_main').attr({action:"http://path/to/save.php"});
$('form#form_main').submit(); })

I can get the submit button to work and the above button to work.

The issue I am having is that I have jquery validation in the form and whenever I hit the SAVE button it wants to validate the form (which I dont want it to as I want it to save at any point in the form).

Does anyone know of a quick way to bypass validation code in jquery. Say with using an ajax call and form submit or someway to say if the SAVE button is clicked ignore the validation plugin.

Thanks for any help.

Recommended Answers

All 2 Replies

cJay,

You're half way there.

Assuming both buttons are both of type="submit" , you can do something like this :

document.ready(function(){

	$("#saveform_ns").click(function(){
		$('form#form_main').attr({action:"http://path/to/save.php"});
		return true;
	});

	$("#processform_ns").click(function(){
		if( validate(this.form) ){
			$('form#form_main').attr({action:"http://path/to/process.php"});
			return true;
		}
		else {
			alert('Sorry, form did not validate');
			return false;
		}
	});

});

Just make sure that your validate function returns true (valid) or false (not valid).

Airshow

Hey thanks Airshow,

I kind of see how your saying to do to get it to work with 2 form buttons. As for the bypassing of Jquery validation plugin - I guess there's an undocumented (as Ive read) solution of simply putting <button type="submit" class="cancel">Save</button>.

Can't believe I missed that, my apologizes but as always thank you very much for your time, take it easy...

Cjay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.