How to cancel a form submit in jquery?

I am trying to cancel a form submit on an add page if the fields don’t validate

I am trying to do this:

$(‘#fdns_recordsadd’).on(‘submit’, function(e) {
if(!/[1]+$/.test($(‘#x_name’).val())){
$(this).val(‘’);
// e.stopPropagation();
e.preventDefault();
return false;
}
});

Such that if the “name” field is not the character types I want, then I null the field and dont submit the form.
However while it seems to null the field it still submits the add form.


  1. A-Za-z0-9- ↩︎

You should write your Javascript/jQuery code in “Form_CustomValidate” under the “Client Scritps” → “Table-Specific” → “Add/Copy Page” or “Edit Page”.

Please read “Server Events and Client Scripts” topic from PHPMaker Help menu for more info and example.