dongzongzi0379 2016-05-16 10:35
浏览 116
已采纳

按钮(提交)不起作用 - 但输入(提交)工作

I want to make Login page with PHP.

And want to use button but it didn't works.
and it looks like just refresh the page.

I tried button tag in the form.
How can I make this works??

<?php
  include "login.php";
?>

<form method="post" id="sign">

  <div class="mdl-textfield mdl-js-textfield">
    <input class="mdl-textfield__input" type="email" name="user_mail" id="user_mail" value="<?php echo addslashes($_POST['user_mail'] ?? '') ?>">
    <label class="mdl-textfield__label" for="user_mail">Email</label>
  </div>

  <div class="mdl-textfield mdl-js-textfield">
    <input class="mdl-textfield__input" type="password" name="passcode" id="passcode" value="<?php echo addslashes($_POST['passcode'] ?? '') ?>">
    <label class="mdl-textfield__label" for="passcode">Password</label>
  </div>
</form>

//this <input> works
<input type="submit" name="signup" form="sign"/>
//I want to use this <button>
<button type="submit" name"signup" form "sign" formmethod="post"></button>

<?php
  if ($error ?? '') {

    echo addslashes($error);

  }

login.php

if ($_POST['signup'] ?? '') {

  $error = '';

  if (!$_POST['user_mail']) $error .= "<br />Please enter email";
  else if (!filter_var($_POST['user_mail'], FILTER_VALIDATE_EMAIL)) $error .= "<br />Please enter valid email";

  if (!$_POST['passcode']) $error .= "<br />Please enter password";
  else {

    if (strlen($_POST['passcode']) < 8) $error .= "<br />Please enter a password more than eight";
    if (!preg_match('`[A-Z]`', $_POST['passcode'])) $error .= "<br />please least one capital letter";

  }

  if ($error) $error = "there were errors:" . $error;
  • 写回答

4条回答 默认 最新

  • dongyuan9149 2016-05-16 10:39
    关注

    <button> means put a button on the page and execute whatever is in the onclick method. <submit> submits a form.

    If you want a button to sumbit your form, use the onclick method of the button to do it. Why can't you use submit, though?

    See here, they use a link <a onclick='...' but you can do the same for your button: How to submit a form with JavaScript by clicking a link?

    As @Arun says below, you can use:

    <button type='submit'> inside your form, too. There are lots of ways to do things, so my only advice on top of this is to be consistent. I use input out of habit, and that way I don't have a bunch of mixed conventions throughout my code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码