简体   繁体   English

页面上的第二个表单未执行任何操作

[英]Second form on page not performing any action

I have two forms on a page. 我在页面上有两种形式。 The first is simply to allow the user to access blocked content. 第一个只是允许用户访问被阻止的内容。 (I understand the risks associated with going this route, but it's just to allow members to view certain information that does not pose any sort of risks). (我了解使用此方法会带来的风险,但这只是为了允许成员查看不会带来任何风险的某些信息)。

This is at the top of the page... 这是页面的顶部...

<?php
    if (isset($_POST['password']) && $_POST['password'] == 'password') {
        setcookie("password", 'password', strtotime('+1 day'));
        header('Location: index.php');
        exit;
    }
?>
.....
<form method="POST">
   <input type="text" name="password">
   <input type="submit" class="btn btn-full" value="Continue" />
</form>

I believe this is preventing the second form (below) from operating (when you click the submit button, nothing happens. It's as if you hadn't hit the button at all). 我认为这将阻止第二种形式(下)的运行(当您单击“提交”按钮时,什么也没有发生。好像您根本没有按下按钮一样)。

<form action="handler.php" method="post" class="contactForm">
    <div class="form-group">
        <input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
        </div>
        <div class="form-group">
                <input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
        </div>
        <div class="form-group">
                <input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
         </div>
         <div class="form-group">
                <textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
         </div>
    <div class="text-center">
        <input type="submit" value="Send Message" class="btn btn-full" />
    </div>
</form>

What can I do to fix the first part to allow the second form to function? 我该怎么做才能修复第一部分以允许第二种形式起作用?

Well, I tried it and it worked. 好吧,我尝试了一下,它奏效了。

1) Make sure you have the handler.php file at the directory of index.php(according to your code). 1)确保在index.php目录下有该handler.php文件(根据您的代码)。

2) Check for any console errors. 2)检查是否有任何控制台错误。 If there is any then please attach it to your post. 如果有,请将其附加到您的帖子中。

3) and did you override the form submit event or input button press event from js? 3),您是否覆盖了js的表单提交事件或输入按钮按下事件?

Also I don't see anything where you are restricting the second form to appear when password is not set in cookie.. so better use: 此外,在cookie中未设置密码的情况下,我也看不到任何限制第二种形式出现的地方。所以更好地使用:

<?php
if (isset($_COOKIE['password'])): ?>

YOUR SECOND FORM

<?php endif; ?>

and hide the first form when password is entered. 并在输入密码时隐藏第一个表格。

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

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