简体   繁体   中英

Javascript Form Validation with Spring WebFlow

I am trying to find a way to do some Javascript Form Validation with Spring WebFlow.

I have the following code in my JSP

<INPUT tabIndex="46" value="Submit" type="submit" name="_eventId_submit" onClick="return dontSubmit();"> 

that runs a JavaScript function and returns false is the form does not pass validation but my page is still getting submitted to the server. I don't want it submitted if I found a validation error

I also tried:

<INPUT tabIndex="46" value="Submit" type="submit" name="_eventId_submit" onsubmit="return dontSubmit();"

and again if find a error the form still gets submitted. please I tried:

<form:form modelAttribute="visit" action="${flowExecutionUrl}" onsubmit="dontSubmit()">

and again the form gets submitted with and without errors..... please help below you will find the funcation

function dontSubmit()
{
    alert("DONT SUBMITTED TO SERVER");
    return false;
}

Place the onsubmit on the FORM tag:

<FORM action="..." onsubmit="return checkrequired();" method="POST">
   <INPUT tabIndex="46" value="Submit" type="submit" name="_eventId_submit" >

See JavaScript Form Validation .

Generally a form validation is done using something like the following:

<form action="server.action" method="POST" onSubmit="return validate(this);">
<input .../>

<input type="submit" name="Submit the form"/>
</form>

where this in the validate function is a reference to the form

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM