/    Sign up×
Community /Pin to ProfileBookmark

Confirmation sentence

Hello to everybody! I have created email form with HTML and PHP. Everything works well. I want to do next thing. When somebody click on submit button, that under form appears confirmation sentence. For example, “thanks on message”. I have code, but it takes me on other page, when I click on submit button, and I don’t want it. So, when somebody sent mail, I want under email form, confirmation sentence appears. Thanks.
HTML

[code]<div class=”form”>
<form method=”post” name=”emailform” action=”form-to-email.php”>

<input type=”text” name=”name” placeholder=”Your Name”>
<input type=”email” name=”email” required=”” placeholder=”Your Email”>
<input type=”text” name=”phone” placeholder=”Your Phone”>
<input type=”text” name=”address” placeholder=”Your Address”>
<input required=”” type=”text” name=”date” placeholder=”Your Desired Termin” onfocus=”(this.type=’date’)”>
<textarea placeholder=”Your Message” name=”message” onkeyup=”adjust_textarea(this)”></textarea>
<input type=”submit” class=”send” name=”submit” value=”SEND”>
</form>


</div>/code]

PHP
[code]<?php
ob_start();
if(!isset($_POST[‘submit’]))
{
//This page should not be accessed directly. Need to submit the form.
echo “error; you need to submit the form!”;
}
$name = $_POST[‘name’];
$visitor_email = $_POST[’email’];
$phone = $_POST[‘phone’];
$address = $_POST[‘address’];
$date = $_POST[‘date’];
$message = $_POST[‘message’];

//Validate first
if(empty($name)||empty($visitor_email)||empty($phone))
{
echo “Name,email and telefon are mandatory!”;
exit;
}

if(IsInjected($visitor_email))
{
echo “Bad email value!”;
exit;
}

$email_from = $visitor_email;//<== update the email address
$email_subject = “Message from $name”;
$email_body = “Your message has been successfully sent to Woodcity using online contact form. “.
“Here is the message:n $message n”.
“Here is my address:n $address n”.
“Here is my phone:n $phone n”.
“Here is my wanted date:n $date n”.



$to = “[email protected], $visitor_email”;//<== update the email address
$headers = “From: $email_from rn”;
$headers .= “Reply-To: $visitor_email rn”;
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header(‘Location: form confirmation.html’);

// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(‘(n+)’,
‘(r+)’,
‘(t+)’,
‘(%0A+)’,
‘(%0D+)’,
‘(%08+)’,
‘(%09+)’
);
$inject = join(‘|’, $injections);
$inject = “/$inject/i”;
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 22.2020 — You could send back the original page with all of your inputs showing again as well as the message. Pretty simple to do. Add value attributes to your input tags and use the php vars that you copied the POST values into in them. Re-arrange your script to do the php stuff FIRST and when done fall into the html code that either shows any error messages all at once, or show the form with your confirmation message.
×

Success!

Help @Hera-Coder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...