简体   繁体   中英

Submit button in a PHP form is unclickable

The problem is the submit button, it's just unclickable, and nothing really happens (=screen doesn't change) when I am trying to submit an email to myself by using the form.

This is my code:

<div class="col-sm-6">
<h4 class="font-alt">Get in touch</h4>
<br>
<form id="contact-form" role="form" novalidate="">
<div class="form-group">
<label class="sr-only" for="cname">Name</label>
<input type="text" id="cname" class="form-control" name="cname"       placeholder="Name*" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>

<div class="form-group">
<label class="sr-only" for="cemail">Your Email</label>
<input type="email" id="cemail" name="cemail" class="form-control" placeholder="Your E-mail*" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>

<div class="form-group">
<textarea class="form-control" id="cmessage" name="cmessage" rows="7" placeholder="Message*" required="" data-validation-required-message="Please enter your message."></textarea>
<p class="help-block text-danger"></p>
</div>

<div class="text-center">
<button type="submit" class="btn btn-block btn-round btn-d">Submit</button>
</div>

</form>
<div id="contact-response" class="ajax-response font-alt"></div>
</div>

And this is the PHP I'm working with:

<?php
// Mail settings
$to = "info@liannesiemensma.com";
$subject = "Contact form";
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["message"])) {

$content  = "Name: "     . $_POST["name"]    . "\r\n";
$content .= "Email: "    . $_POST["email"]   . "\r\n";
$content .= "Message: "  . "\r\n" . $_POST["message"];

if (mail($to, $subject, $content, $_POST["email"])) {

$result = array(
"message" => "Thanks for contacting me! I will do my best to reply in a timely manner.",
"sendstatus" => 1
);

echo json_encode($result);
} else {

$result = array(
"message" => "Sorry, something is wrong.",
"sendstatus" => 0
);

echo json_encode($result);
}
}
?>

What am I doing wrong?

write form tag action="fileName.php" and method

Ex: <form id="contact-form" role="form" novalidate="" action="#" method="post">

actuly your form is submitting properly on same page just add

<?php
print_r($_GET);
?>

add this at first line and check

You are missing an action and method tags in your form declaration like this example:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

Then you need to rename your file with extension .php and do some php processing in <?php ?> tags. You can validate your fields by utilising isset() method like this example:

isset($_POST["cname"])

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.

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