简体   繁体   中英

Form submission with php after js validation

I want to submit my form to a PHP file called regier.php after validating it using JavaScript. The HTML form is given below:

HTML FORM:

<form onsubmit="return validateForm()" action="register.php" method="post" class="sign-up-form">

<div class="input-field">
   <input type="text" placeholder="Nome" name="username" id="username" onkeyup="validateName()"
   <span id="name-error"></span>
</div>

<div class="input-field">
  <input name="password" type="password" placeholder="Password" id="password"      onkeyup="validatePassw()" />
   <span id="passw-error"></span>
</div>

<input onclick="return validateForm()" type="submit" class="btn" value="Registrati">

JAVASCRIPT VALIDATION: The following is the JavaScript validation code:

function validateForm() {
    if (!validateName()) {
        validateName()
    }
    if (!validateEmail()) {
        validateEmail()
    }
    if (!validatePassw()) {
        validatePassw()
    }
}```

Set the action attribute to a file/code to validate the form:

 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

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