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:
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
. 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. After removing this:
event.preventDefault(); // prevent default submit behaviour
The form is now working. Thanks all for the help :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.