dqmq0654 2015-01-19 16:39
浏览 19

为什么JS警报会杀死我的注册表单?

I just finished my first working registration form connected to a database. Actually, it's basically a copy of a tutorial demo @ http://jqueryvalidation.org/files/demo/milk/ except I had to add the database stuff.

I still have one minor bug. The form doesn't work unless I delete this code:

// specifying a submitHandler prevents the default submit, good for the demo
submitHandler: function() {
alert("submitted!");
},

It's kind of trivial, but it would be nice if the user could see some sort of "Success" message when they click the Submit button. I didn't want to post all the code, but I have a live page @ http://www.govwa.org/test/registration.php

This is the PHP code that I inserted just before the form closing tag:

include('config.php');
$pdo = connect();

// adding new member using PDO with try/catch to escape the exceptions
try {
 $sql = "INSERT INTO g1_members (firstname, lastname, username,  password, password_confirm, email) VALUES (:firstname, :lastname,  :username, :password, :password_confirm, :email)";
  $query = $pdo->prepare($sql);
  $query->bindParam(':firstname', $_POST['firstname'], PDO::PARAM_STR);
  $query->bindParam(':lastname', $_POST['lastname'], PDO::PARAM_STR);
  $query->bindParam(':username', $_POST['username'], PDO::PARAM_STR);
  $query->bindParam(':password', $_POST['password'], PDO::PARAM_STR);
  $query->bindParam(':password_confirm', $_POST['password_confirm'],  PDO::PARAM_STR);
  $query->bindParam(':email', $_POST['email'], PDO::PARAM_STR);
  $query->execute();
  } catch (PDOException $e) {
  echo 'PDOException : '.  $e->getMessage();
 }

Does anyone have a hunch what the problem might be? Alternatively, is there another way of displaying a message when someone clicks the Submit button?

  • 写回答

1条回答 默认 最新

  • douye2036 2015-01-19 16:42
    关注

    The submitHandler replaces the default submit, so the form is never submitted when you add that handler, you have to do it manually.

    From the documentation

    Callback for handling the actual submit when the form is valid. Gets the form as the only argument. Replaces the default submit. The right place to submit a form via Ajax after it is validated.

    either remove it, or submit the form once valid in the handler

    submitHandler: function(form) {
        alert("submitted!");
        form.submit()
    },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么