简体   繁体   English

我有一个登录页面。 我想在表单中添加多个操作,或者有另一种解决方案

[英]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.

相关问题 我想要在 html 页面上一次一个字符。 完成后加载下一个 - I want one character at a time on html page. After completion load next one 我有一个按钮可以重定向另一个表单我希望下拉列表中的该按钮值作为下一页表单中的选定选项? - I have a button that redirects the another form I want that button value in the dropdown as a selected option in the next page form? 我想在同一个html页面中从一种形式转换为另一种形式,例如问题答案测验页面 - I want to move from one form to another in same html page ,like a question answer quiz page 我有一个包含多个跨度元素的弹出 div 如何显示另一个跨度 - I have a popup div with more than one span element how to display another span .NET仅当3个用户(或说一个以上)登录时才打开网页。 想要采购投标申请书 - .NET how to open a wepage only when 3 users( or say more than one) login. I want it for procurement bidding application 我希望{{dish.name}}显示在html页面中。 - I want {{dish.name}} to be displayed in an html page. 如何做到这一点我希望如果用户单击标记的图像而不是卷轴开始在其他页面上播放我在一个项目中有一个项目 - How to do this I want that if a user click on the marked image than reels start playing on other page i have one project in one project 当我单击注销按钮时,会打开确认警报。 当我取消时,它将重定向登录页面,但我想重定向当前页面。 我该怎么做? - When i click in logout button open a confirm alert. When i cancel it will redirect login page but i want to redirect current page. How i can do it? 我需要在一个网页中制作多个模态 - I need to make more than one modal in one web page 一个表单可以有多个onsubmit()吗? - Can a form have more than one onsubmit()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM