[英]HTML for is not being submitted after clicking on the submit button
I have the following form:我有以下表格:
<form method="post">
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Full Name:</label>
<input type="text" class="form-control" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Email Address:</label>
<input type="email" class="form-control" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Description</label>
<textarea placeholder="Your text here.." name="description" class="form-control" rows="8" required></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<input type="submit" value="Send" name="submit" class="btn btn-success btn-block btn-lg">
</form>
And in the same file below the form, I have the following php form statement where I check if the form is submitted or not:在表单下方的同一个文件中,我有以下 php 表单语句,用于检查表单是否已提交:
if (isset($_POST['submit'])) {
echo "<h1>" . "Form is submitted" . "</h1>";
} else {
echo "<h1>" . "Form is not submitted" . "</h1>";
}
After clicking the "Send" button I cannot enter the "Form is submitted" if
.单击“发送”按钮后, if
. I'm not sure why?我不确定为什么?
This should work, the naming of the submit button wasn't working.这应该有效,提交按钮的命名不起作用。
<?php
if (isset($_POST['SubmitForm'])) {
echo "<h1>" . "Form is submitted" . "</h1>";
} else {
echo "<h1>" . "Form is not submitted" . "</h1>";
}
?>
<form method="post">
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Full Name:</label>
<input type="text" class="form-control" name="name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Email Address:</label>
<input type="email" class="form-control" name="email" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label class="contact-p1">Description</label>
<textarea placeholder="Your text here.." name="description" class="form-control" rows="8" required></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<input type="submit" value="Send" name="SubmitForm" class="btn btn-success btn-block btn-lg">
</form>
The problem was in the JavaScript file for the contact form.问题出在联系表单的 JavaScript 文件中。 After removing this:删除后:
event.preventDefault(); // prevent default submit behaviour
The form is now working.该表格现在正在工作。 Thanks all for the help :)谢谢大家的帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.