-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added first version of contact form script
- Loading branch information
0 parents
commit 4c58710
Showing
3 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
session_start(); | ||
$int1 = rand(1,10); | ||
$int2 = rand(1,10); | ||
|
||
while(($int1 - $int2) < 0) { | ||
$int1 = rand(1,10); | ||
$int2 = rand(1,10); | ||
if(($int1 - $int2) > 0) break; | ||
} | ||
|
||
if($int1 > $int2) { | ||
$method = 'plus'; | ||
} | ||
else $method = 'subtract'; | ||
|
||
switch($method) { | ||
case 'plus': | ||
$answer = $int1 + $int2; | ||
break; | ||
case 'subtract': | ||
$answer = $int1 - $int2; | ||
break; | ||
} | ||
|
||
$question = 'What does '.$int1.' '.$method.' '.$int2.' make?'; | ||
|
||
$_SESSION['question'] = (string) $answer; | ||
|
||
?> | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Contact Form Template</title> | ||
<meta charset="utf-8" /> | ||
<link rel="stylesheet" href="styles.css" /> | ||
</head> | ||
<body> | ||
<div class="content"> | ||
<h1>Contact Form</h1> | ||
<p>Alec's contact form template.</p> | ||
<form action="send.php" method="post" class="contact-form"> | ||
<fieldset> | ||
<p> | ||
<label> | ||
Name: | ||
<input type="text" id="name" name="name" autocomplete="on" required="required" /> | ||
</label> | ||
</p> | ||
<p> | ||
<label>Email: | ||
<input type="email" id="email" name="email" autocomplete="on" required="required" /> | ||
</label> | ||
</p> | ||
<p> | ||
<label>Phone: | ||
<input type="tel" id="phone" name="phone" placeholder="(not required)" autocomplete="on" /> | ||
</label> | ||
</p> | ||
<p> | ||
<label>Options: | ||
<select id="option" name="option"> | ||
<option value="Option 1">Option 1</option> | ||
<option value="Option 2">Option 2</option> | ||
<option value="Option 3">Option 3</option> | ||
</select> | ||
</label> | ||
</p> | ||
<p> | ||
<label>Message: | ||
<textarea id="message" name="message" required="required" rows="10"></textarea> | ||
</label> | ||
</p> | ||
<p> | ||
<label><?php echo($question) ?> | ||
<input type="text" id="question" name="question" placeholder="(just for security)" autocomplete="off" required="required" /> | ||
</label> | ||
</p> | ||
<p> | ||
<button>Send message</button> | ||
</p> | ||
</fieldset> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
session_start(); | ||
$mailto = 'me@alecrust.com' ; | ||
$subject = "Contact Form Message" ; | ||
$formurl = "index.php" ; | ||
$errorurl = "error.php" ; | ||
$thankyouurl = "success.php" ; | ||
$name = $_POST['name'] ; | ||
$email = $_POST['email'] ; | ||
$phone = $_POST['phone'] ; | ||
$message = $_POST['message'] ; | ||
$http_referrer = getenv( "HTTP_REFERER" ); | ||
if (!isset($_POST['email'])) { | ||
header( "Location: $formurl" ); | ||
exit ; | ||
} | ||
if (empty($name) || empty($email) || empty($phone) || empty($message) || $_SESSION['answer'] != $_POST['answer']) { | ||
header( "Location: $errorurl" ); | ||
exit ; | ||
} | ||
$name = strtok( $name, "\r\n" ); | ||
$email = strtok( $email, "\r\n" ); | ||
$phone = strtok( $phone, "\r\n" ); | ||
if (get_magic_quotes_gpc()) { | ||
$message = stripslashes( $message ); | ||
} | ||
$messageproper = | ||
"Name: " . $name ."\n" . | ||
"Email: " . $email ."\n" . | ||
"Phone: " . $phone ."\n\n" . | ||
"Message: " . $message ."\n" ; | ||
mail($mailto, $subject, $messageproper, "From: \"$name\" <$email>\r\nReply-To: \"$name\" <$email>\r\n" ); | ||
header( "Location: $thankyouurl" ); | ||
exit ; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Misc Styles (ignore) */ | ||
body{font-family:sans-serif;background:#eee}.content{width:830px;margin:auto;padding:10px;background:#fff} | ||
|
||
/* Contact Form styles ---------- */ | ||
|
||
/* Main <form> container */ | ||
.contact-form fieldset { border: 0; } | ||
|
||
.contact-form p { margin: 0 0 15px; } | ||
|
||
.contact-form input[type=text], | ||
.contact-form input[type=email], | ||
.contact-form input[type=tel], | ||
.contact-form textarea, | ||
.contact-form select { | ||
display: block; | ||
padding: 5px; | ||
width: 98%; | ||
} | ||
|
||
.contact-form select { width: auto; } | ||
|
||
.contact-form button { padding: 5px; } |