Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set email variables
- $email_to = 'es.com.au';
- $email_subject = 'Form submission';
- // Set required fields
- $required_fields = array('fullname','email','comment','phone','street','town','reCAPTCHA');
- // set error messages
- $error_messages = array(
- 'fullname' => 'Please enter in a Name to proceed.',
- 'email' => 'Please enter in a valid Email Address',
- 'comment' => 'Please enter your Message to continue.',
- 'phone' => 'Please enter in a valid phone number',
- 'street' => 'Please enter in your Street Address',
- 'town' => 'please enter in your Town',
- 'reCAPTCHA' => 'Please enter in the reCaptcha correctly',
- );
- // Set form status
- $form_complete = FALSE;
- // configure validation array
- $validation = array();
- // check form submittal
- if(!empty($_POST)) {
- // Sanitise POST array
- foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
- // Loop into required fields and make sure they match our needs
- foreach($required_fields as $field) {
- // the field has been submitted?
- if(!array_key_exists($field, $_POST)) array_push($validation, $field);
- // check there is information in the field?
- if($_POST[$field] == '') array_push($validation, $field);
- // validate the email address supplied
- if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
- }
- // basic validation result
- if(count($validation) == 0) {
- // Prepare our content string
- $email_content = 'New Website Comment: ' . "\n\n";
- // simple email content
- foreach($_POST as $key => $value) {
- if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
- }
- // if validation passed ok then send the email
- mail($email_to, $email_subject, $email_content);
- // Update form switch
- $form_complete = TRUE;
- }
- }
- function validate_email_address($email = FALSE) {
- return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
- }
- function remove_email_injection($field = FALSE) {
- return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
- }
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <title>Contact Form</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <link href="contact/css/contactform.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools-yui-compressed.js"></script>
- <script type="text/javascript" src="content/validation/validation.js"></script>
- </script>
- <script type="text/javascript">
- var nameError = '<?php echo $error_messages['fullname']; ?>';
- var streetError = '<?php echo $error_messages['street']; ?>';
- var townError = '<?php echo $error_messages['town']; ?>';
- var emailError = '<?php echo $error_messages['email']; ?>';
- var commentError = '<?php echo $error_messages['comment']; ?>';
- var phoneError = '<?php echo $error_messages['phone']; ?>';
- var reCAPTCHAError ='<?php echo $error_message['reCAPTCHA']; ?>';
- function MM_preloadImages() { //v3.0
- var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
- var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
- if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
- }
- </script>
- <link href="default.css" rel="stylesheet" type="text/css" />
- </head>
- <body onLoad="MM_preloadImages('content/images/x.png')">
- <div id="header">
- <div id="menu">
- <ul>
- <li class="active"><a href="http://.tk/#">Home</a></li>
- <li class="active"><a href="http://.tk/contact.php">Contact Form</a></li>
- <li><a href="http:///.php">FileZilla</a></li>
- <li><a href="http://.tk/Captchaguide.php">CAPTCHA</a></li>
- <li><a href="#">Link 3</a></li>
- <li><a href="#">Link 4</a></li>
- </ul>
- </div>
- <div id="logo">
- <h1><a href="#">y</a></h1>
- <h2><a href="#">e</a></h2>
- </div>
- </div>
- <!-- end header -->
- <div id="formWrap">
- <h2>We Appreciate Your Feedback</h2>
- <div id="form">
- <?php if($form_complete === FALSE): ?>
- <form action="contact.php" method="post" id="comments_form">
- <div class="row">
- <div class ="label">Your Name</div> <!-- end .label -->
- <div class = "input">
- <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" />
- <?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>
- </div><!-- end .input -->
- <div class="context">e.g John Smith</div><!-- end .context -->
- </div><!-- end .row -->
- <div class="row">
- <div class ="label">Street Address</div> <!-- end .label -->
- <div class = "input">
- <input type="text" id="street" class="detail" name="street" value="<?php echo isset($_POST['street'])? $_POST['street'] : ''; ?>" />
- <?php if(in_array('street', $validation)): ?><span class="error"><?php echo $error_messages['street']; ?></span><?php endif; ?>
- </div><!-- end .input -->
- <div class="context"> We will not use this information for commercial purposes</div>
- </div><!-- end .row -->
- <div class="row">
- <div class ="label">Town</div> <!-- end .label -->
- <div class = "input">
- <input type="text" id="town" class="detail" name="town" value="<?php echo isset($_POST['town'])? $_POST['town'] : ''; ?>" />
- <?php if(in_array('town', $validation)): ?><span class="error"><?php echo $error_messages['town']; ?></span><?php endif; ?>
- </div><!-- end .input -->
- <div class="context"> We will not use this information for commercial purposes</div>
- </div><!-- end .row -->
- <div class="row">
- <div class ="label">Phone Number</div> <!-- end .label -->
- <div class = "input">
- <input type="text" id="phone" class="detail" maxlength="10" name="phone" value="<?php echo isset($_POST['phone'])? $_POST['phone'] : ''; ?>" />
- <?php if(in_array('phone', $validation)): ?><span class="error"><?php echo $error_messages['phone']; ?></span><?php endif; ?>
- </div><!-- end .input -->
- <div class="context">We will not share your Phone Number</div>
- </div><!-- end .row -->
- <div class="row">
- <div class ="label">Your Email Address</div> <!-- end .label -->
- <div class = "input">
- <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" />
- <?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?>
- </div><!-- end .input -->
- <div class="context">We will not share you email with anyone or spam.</div>
- </div><!-- end .row -->
- <div class="row">
- <div class ="label">Your Message</div> <!-- end .label -->
- <div class = "input">
- <textarea id= "comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea>
- <?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>
- <?php require_once('recaptchalib.php');
- $publickey = "6LcKbeUSAAAAAPebMsf38ZsbLs1pkkj-W6JRoxaS"; // you got this from the signup page
- echo recaptcha_get_html($publickey);
- ?>
- <?php
- if (isset($_POST['submit'])){
- require_once('recaptchalib.php');
- $privatekey = "6LcKbeUSAAAAABoenA5RB81vs59VIWIQvkU41vHE";
- $resp = recaptcha_check_answer ($privatekey,
- $_SERVER["REMOTE_ADDR"],
- $_POST["recaptcha_challenge_field"],
- $_POST["recaptcha_response_field"]);
- if (!$resp->is_valid) {
- // What happens when the CAPTCHA was entered incorrectly
- }
- else {// What happens when it was successful.};
- }
- ?>
- <!--Error Checking -->
- </div><!-- end .input -->
- </div><!-- end .row -->
- <!-- submist button -->
- <div class="submit">
- <input name="submit" id="submit" type="submit" value="Submit" />
- <?php else:?>
- <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; text-align:center;">Thank you for your Message!</p>
- <script type="text/javascript">
- setTimeout('ourRedirect()', 5000)
- function ourRedirect(){
- location.href='contact.php'
- }
- </script>
- <script language="javascript">
- var time_left = 5;
- var cinterval;
- function time_dec(){
- time_left--;
- document.getElementById('countdown').innerHTML = time_left;
- if(time_left == 0){
- clearInterval(cinterval);
- }
- }
- cinterval = setInterval('time_dec()', 1000);
- </script>
- <p style="font-size:20px; font-family:Arial, Helvetica, sans-serif; color:#000; font-weight:bold; text-align:center;13px;">Redirecting In <span id="countdown">5</span>.</p>
- <?php endif; ?>
- </div><!-- End .submit -->
- </form>
- <!-- end .context -->
- </div><!-- end .row -->
- </div>
- <!-- end #form-->
- </div>
- </body>
- <!-- end page -->
- <div id="footer">
- <p id="legal">©2013 All Rights Reserved.</p>
- </div>
- </html>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement