/    Sign up×
Community /Pin to ProfileBookmark

How to insert this code into a template?

I have a page that contains a contact form that uses the following code for submission of the form.
Can you show me how to get the following messages to appear in a page that looks the same as the rest of the website instead of a white page with only these messages written:

“You didn’t fill in these required fields: Please returnto the previous page and try again”

“The e-mail you provided is not valid. Please return to the previous page and try again.”

“Thank you for your feedback. We will get back to you shortly.”

Here’s the PHP code:

[code=php]<?
// This is the beginning of the PHP code

$name = $_POST[‘name’];
$email = $_POST[’email’];
$comments = $_POST[‘comments’];
$error_msg = “”;
$msg = “”;

if(!$email){
$error_msg .= “Your email n”;
}
if($email){
if(!eregi(“^[a-zA-Z0-9_.-]+@[a-zA-Z0-9._-]+.[a-zA-Z]{2,4}”, $email)){
echo “n<br>The e-mail you provided is not valid. Please <a href=”javascript:history.back()”>return</a> to the previous page and try

again.n<br>”;
exit;
}
$msg .= “Email: t $email n”;
}

if($comments){
$msg .= “Comments: t $comments n”;
}
$sender_email=””;

if(!isset($name)){
if($name == “”){
$sender_name=”Web Visitor”;
}
}else{
$sender_name=$name;
}
if(!isset($email)){
if($email == “”){
$sender_email=”[email protected]”;
}
}else{
$sender_email=$email;
}
if($error_msg != “”){
echo “You didn’t fill in these required fields:<br>”
.nl2br($error_msg) .'<br>Please <a href=”javascript:history.back()”>return</a> to the previous page and try again.’;
exit;
}
$mailheaders = “MIME-Version: 1.0rn”;
$mailheaders .= “Content-type: text/plain; charset=iso-8859-1rn”;
$mailheaders .= “From: $sender_name <$sender_email>rn”;
$mailheaders .= “Reply-To: $sender_email <$sender_email>rn”;
mail(“[email protected]”,”Website Contact”,stripslashes($msg), $mailheaders);
echo “<html>n<head>n<title>PAGE 1</title>n</head>n<body>n<h1>Thank you for your feedback. We will get back to you shortly.</h1>n”;
‘</body></html>’;
//This is the end of the PHP code
?>[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Bootsman123Jul 13.2005 — Instead of echo'ing you should capture the messages and print them on the place you want them to be printed.
Copy linkTweet thisAlerts:
@hitmanauthorJul 13.2005 — Can you show me how to do this?
Copy linkTweet thisAlerts:
@Bootsman123Jul 13.2005 — Instead of:
[code=php]
echo "Lorem Ipsum";
// More code...
echo "Lorem Ipsum2";
[/code]


You can do this:
[code=php]
$msg = "";
$msg .= "Lorem Ipsum";
// More code...
$msg .= "Lorem Ipsum2";
// Your code starts here.
echo $msg;
[/code]
Copy linkTweet thisAlerts:
@hitmanauthorJul 13.2005 — Thanks a lot!
×

Success!

Help @hitman 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.29,
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,
)...