What is recommend (right) way to <form submit> action?


#1

Hello.

I want to know how to write from submit code.

I am using below code.

$('.ui.form').form({
	keyboardShortcuts: false,
	fields: {
	
	...
        some validation code
        ...

	}
}).api({
	action: 'account submit',
	method: 'POST',
	data: {
        ...
    	},
	beforeSend: function(settings) {
                ...
		return settings;
	},
	successTest: function(response) {
		// test whether a JSON response is valid
		return response.success || false;
	},
	onSuccess: function(response) {
		$('.ui.modal .content').html('<p><b>' + response.message + '</b></p>');
		$('.ui.modal').modal('show');
	},
	onFailure: function(response) {
		console.log(response);
		$('.ui.modal .content').html('<p><b>' + response.message + '</b></p>');
		$('.ui.modal').modal('show');
	}
});

some other user wrote code like below,

$('.form').form({
    fields: {
    },
    onSuccess: function() {
        $.ajax( ... );
    }
});

Which is recommended? and I want to prevent enter key and if submit successfully, show modal and then refresh pageā€¦