[英]I have a login page. I want to put more than one action in form, or there is another solution
I have a login page and I have a php & javascript page.我有一个登录页面,我有一个 php 和 javascript 页面。 I want to link form to javascript and php code html loin page我想将表格链接到 javascript 和 php 代码 html 腰部页面
<form action="INDEX.PHP" method="POST" class="two">
<div>
<button class="yeu" id="submit" type="submit" name="submit" onclick="validate();validatewoman();validateuser();">login</button>
<input type="text" name="username" id="username" maxlength="14">
</div>
<div id="user" style="color: black; font-size: 20px; text-align: left;">
<pre style="color: black; font-size: 20px; text-align: left; display: none;"></pre>
</form>
php php
<?php
$conn = mysqli_connect('localhost','root','root','login');
if(!$conn){
echo "data base error";
}
if (isset($_POST['submit'])){
$username = $_POST['username'];
$sql = "INSERT INTO login_table(login) VALUES ('$username')";
if(!mysqli_query($conn , $sql)){
echo 'error: '. mysqli_error($conn);
}
}
?>
javascript javascript
function validate(){
var user_one = document.getElementById("username").value;
if (
user_one=== "578815452122"
){
else{
document.write = "user error" ;
};
};
You can use the onsubmit
Event Listener , like this:您可以使用onsubmit
事件侦听器,如下所示:
const myform = document.getElementsByClassName('two')[0];
function validate (e) { ... }
myform.addEventListener('submit', validate);
When someone tries to submit your form, the event listener will detect the submit
event and run the validate()
function.当有人尝试提交您的表单时,事件监听器将检测到submit
事件并运行validate()
function。
The form will be submitted only after the function has run.只有在function 运行后才会提交表单。
NB When declaring your validate()
function, you should have the event object
specifically named as a parameter (eg. function validate (event) {...}
or function validate (e) {...}
), such that at any point where you would like the form to not submit, you can invoke event.preventDefault();
NB When declaring your validate()
function, you should have the event object
specifically named as a parameter (eg. function validate (event) {...}
or function validate (e) {...}
), such that at any在您希望表单不提交的地方,您可以调用event.preventDefault();
or e.preventDefault();
或e.preventDefault();
. .
See:看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.