php - What action should my Contact Form have, I am using Angular Routing to get contact.html -
i creating personal website , using angular js routing fast loading. have contact link on navbar , once visitor clicks it. load code in contact.html inside index.html.
contact.html code contains php code , html form. in part of code using mail() sending email myself once form filled visitor.
when visitor clicks submit button, incorrect information or incomplete data, page suppose store data user provided in input fields , give errors. contact.html works fine when run on local server.
but when go index.html , click on contact link, contact.html doesn't work expected. whenever submit clicked incorrect or incomplete data, reloads entire contact.html inside index.html instead of throwing errors , storing filled information, suppose do.
how make work properly?
here code
<?php if (isset($_post["submit"])) { $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; $human = intval($_post['human']); $from = 'asfsa'; $to = 'gabanimillin@gmail.com'; $subject = 'message millin gab site '; $body = "from: $name\n e-mail: $email\n message:\n $message"; // check if name has been entered if (!$_post['name']) { $errname = 'please enter name'; } // check if email has been entered , valid if (!$_post['email'] || !filter_var($_post['email'], filter_validate_email)) { $erremail = 'please enter valid email address'; } //check if message has been entered if (!$_post['message']) { $errmessage = 'please enter message'; } //check if simple anti-bot test correct if ($human !== 5) { $errhuman = 'your anti-spam incorrect'; } // if there no errors, send email if (!$errname && !$erremail && !$errmessage && !$errhuman) { if (mail ($to, $subject, $body, $from)) { $result='<div class="alert alert-success">thank you! in touch</div>'; } else { $result='<div class="alert alert-danger">sorry there error sending message. please try again later</div>'; } } } ?> <form class="form-horizontal" role="form" method="post" action=""> <div class="form-group"> <label for="name" class="col-sm-2 control-label">name</label> <div class="col-sm-10"> <input type="text" class="form-control" id="name" name="name" placeholder="first & last name" value="<?php echo htmlspecialchars($_post['name']); ?>"> <?php echo "<p class='text-danger'>$errname</p>";?> </div> </div> <div class="form-group"> <label for="email" class="col-sm-2 control-label">email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="email" name="email" placeholder="example@domain.com" value="<?php echo htmlspecialchars($_post['email']); ?>"> <?php echo "<p class='text-danger'>$erremail</p>";?> </div> </div> <div class="form-group"> <label for="message" class="col-sm-2 control-label">message</label> <div class="col-sm-10"> <textarea class="form-control" rows="4" name="message"> <?php echo htmlspecialchars($_post['message']);?> </textarea> <?php echo "<p class='text-danger'>$errmessage</p>";?> </div> </div> <div class="form-group"> <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label> <div class="col-sm-10"> <input type="text" class="form-control" id="human" name="human" placeholder="your answer"> <?php echo "<p class='text-danger'>$errhuman</p>";?> </div> </div> <div class="form-group"> <div class="col-sm-10 col-sm-offset-2"> <input id="submit" name="submit" type="submit" value="send" class="btn btn-primary"> </div> </div> <div class="form-group"> <div class="col-sm-10 col-sm-offset-2"> <?php echo $result; ?> </div> </div> </form>
Comments
Post a Comment