简体   繁体   English

表单提交按钮不起作用

[英]Form submit button won't work

I can see no problems with my code but whenever I push the submit button, nothing happens: 我可以看到我的代码没有问题,但每当我按下submit按钮时,没有任何反应:

<form id = "form_signin_containers" action = "" method = "post">
    <input type = "text" name = "si_idnumber" placeholder = "ID Number" required/>
    <input type = "password" name = "si_password" placeholder = "Password" required/>
    <input type = "submit" name = "si_submit" value = "    sign in    ">
</form>

I tried adding an isset button to the php code above my html code to test it out: 我尝试在我的html代码上面的php代码中添加一个isset按钮来测试它:

if(isset($_POST['si_submit'])) {
  header("Location:home.php");
}

When I press the submit button it still won't work. 当我按下提交按钮时,它仍然无法正常工作。 I also noticed, since I put a <...required/> on all the textbox, if I should click the submit button, it would notify me if the textboxes are empty right? 我也注意到,因为我在所有文本框上放了一个<...required/> ,如果我点击提交按钮,它会通知我文本框是否为空? But still when I leave the textboxes blank and presses the submit button, it won't do anything, it won't even tell me that the textboxes are empty. 但是当我将文本框留空并按下提交按钮时,它仍然无法执行任何操作,它甚至不会告诉我文本框是空的。 As if the button is dead. 好像按钮已经死了。

UPDATE UPDATE
I have this javascript that I placed right before the </body> that will make the page scroll smoothly whenever I click an anchor button. 我有这个javascript ,我放在</body>之前,只要我点击一个锚点按钮,就会使页面顺利滚动。
Sample of my anchor buttons: 我的锚点按钮示例:

<form id = "form_createaccount_button" action="#createchooserblink">
    <input type="submit" value="  create account  " />
</form> 

The JS: JS:

<script>
  $(function() {
     $('input').click(function(e) {
     e.preventDefault();
     var hash = $(this).parent('form').attr('action');
     var target = $(hash);
     target = target.length ? target : $('[name=' + hash.slice(1) +']');
     if (target.length) {
       $('html, body').animate({
         scrollTop: target.offset().top
       }, 1000);
     }

 });
 });
</script>

Could this be affecting the login forms? 这会影响登录表单吗?

Yes, your JavaScript is preventing form submission: 是的,您的JavaScript阻止了表单提交:

$('input').click(function(e) {
     e.preventDefault();
     // ...

Clicking the submit button triggers that click handler, and preventing the default action prevents form submission. 单击提交按钮会触发该单击处理程序,并阻止默认操作阻止表单提交。

You could specifically leave the name="si_submit" button out of that by adding :not([name=si_submit]) : 你可以通过添加:not([name=si_submit])来专门保留name="si_submit"按钮:

$('input:not([name=si_submit])').click(function(e) {
     e.preventDefault();
     // ...

...but I think instead of doing that, I'd probably use a class or something on the "anchor buttons" (or not use the "anchor buttons" at all), and add that class instead. ...但我认为不是这样做,我可能会在“锚点按钮”上使用类或其他东西(或根本不使用“锚点按钮”),而是添加该类。 Eg: 例如:

<form id = "form_createaccount_button" action="#createchooserblink">
    <input type="submit" class="anchor-button" value="  create account  " />
</form>

and: 和:

$('input.anchor-button').click(function(e) {
     e.preventDefault();
     // ...

Try this: 尝试这个:

<form id="form_signin_containers" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<input type="text" name="si_idnumber" placeholder="ID Number" required>
<input type="password" name="si_password" placeholder="Password" required>
<input type="submit" value="sign in">
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM