我有以下表格:
<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>
在表单下面的同一个文件中,我有以下php表单语句,我检查表单是否已提交:
if (isset($_POST['submit'])) {
echo "<h1>" . "Form is submitted" . "</h1>";
} else {
echo "<h1>" . "Form is not submitted" . "</h1>";
}
点击“发送”按钮后,我无法输入“表单已提交”if
。我不确定为什么?
答案 0 :(得分:-2)
这应该有效,提交按钮的命名不起作用。
<?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>
答案 1 :(得分:-2)
问题出在联系表单的JavaScript文件中。删除后:
event.preventDefault(); // prevent default submit behaviour
表单正在运行。谢谢大家的帮助:))