du9698 2011-05-13 09:50
浏览 11

连接到数据库之前执行工作

i am designing a register form for a site.in this form in html forms we have to password type and a submit button.

<form action="index1.php" method="post">
<b>pass:</b> <input type="password" name="pass" size="25"/>
<b>pass:</b> <input type="password" name="cpass" size="25"/>
<input type="submit" name ="submit" value="comfirm">

on of them are for pass and second for confirm password and a button for submit.

user must fill both of pass and cpass fields until program can store in database

i want that when user click on submit button (for speed up my program) my program check that if two fields are filled are no.if they have filled connect to database and store them into database or if no show a alert to user and doesn't connect to database. my database codes are in index1.php.

if it possible i check them with javascript functions with onclick in submit? (i could retrieve form values into a javascript functions and checked them but could not stop program and so it go to index1.php and connect to database that i don't need)

if yes how? if no how can i do that.

if it possible in javascript me go to a particular page in php for example 5.php?

  • 写回答

1条回答 默认 最新

  • drfif48428 2011-05-13 09:53
    关注

    Use the onsubmit event on the form element:

    <form action="..." onsubmit="return validate_fields();">
    

    The return keyword is important here. Inside your validate_fields, return false if the check fails or true if it succeeds:

    function validate_fields() {
      ...
      if(fields_is_valid) {
        return true;
      }else{
        alert('Fill in all fields!');
        return false;
      }
      ...
    }
    

    This will stop the form from being sent if the validation fails.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作