Jump to content

mdez13

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mdez13's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hey guys, i just grabbed this quick form offline. can anybody help me figure out how to display JS popups about validation errors as opposed to opening a whole new page to display them? also to i'd like to echo the 'thank you' message on the page as opposed to opening a new window as well. i tried echoing the errors as well as creating a 'success' variable to no avail. im not that good with php . can anybody help me out? <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "matt@gmail.com"; $email_subject = "Your email subject line"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['company']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['interest']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $company = $_POST['company']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $interest = $_POST['interest']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The email address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$company)) { $error_message .= 'The company you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$interest)) { $error_message .= 'The area of interest you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The specific requests you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Company: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Area of Interest: ".clean_string($interest)."\n"; $email_message .= "Specific Requests: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- include your own success html here --> Thank you for contacting us. We will be in touch with you very soon. <?php } ?>
  2. im already using a js validator and i've added the variable in there but it doesnt seem to want to work correctly.
  3. this is a form im using. i added in the drop down department and that's where i started running in to trouble since im not so great with php. if i don't choose a department the message returns 'message sent' & 'invalid department'. the form doesn't reset itself after sending also. can anybody help me out? <?php session_start(); $errors = ''; $name = ''; $visitor_email = ''; $visitor_telephone = ''; $visitor_subject = ''; $visitor_hear = ''; $user_message = ''; $your_email = ''; $department = ''; $contactAry = array( 'Sales' => 'sales@email.com', 'Advertising' => 'advertising@email.com', ); if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_telephone = $_POST['telephone']; $visitor_subject = $_POST['subject']; $visitor_hear = $_POST['hear']; $user_message = $_POST['message']; $your_email = $_POST['department']; ///------------Do Validations------------- if(!array_key_exists($_POST['department'], $contactAry)) { $invaliddept = ''; $invaliddept .= "<p class='fail' align='center'>Invalid department</p>"; } else { $your_email = $contactAry[$_POST['department']]; } if(empty($name)||empty($visitor_email)) { $errors .= "\n<p class='captcha-miss' align='center'>Please Fill out Required Fields.</p>"; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email entry!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n <p class='captcha-miss' align='center'>The captcha code does not match!</p>"; } if(empty($errors)) { //send the email $to = $your_email; $subject="Form Submission From Contact Page"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "$name submitted the contact form for $department:\n". "Name: $name\n". "Email: $visitor_email \n". "Telephone: $visitor_telephone \n\n". "How did you hear about us? $visitor_hear \n\n". "Subject: $visitor_subject \n\n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); $success = ''; $success .= "<p class='success' align='center'>Your message sent!</p>"; } } // 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; } } ?> <?php echo $success; ?> <?php echo $invaliddept; ?> <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='department'><strong>Department</strong></label><br> <select name="department" id="department"> <option>Select Department...</option> <?php foreach($contactAry as $department => $your_email) { echo "<option value='$department'>$department</option>\n"; } ?> </select> </p> <p> <label for='name'><strong>Name</strong></label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>' class="contact_input shadow"> </p> <p> <label for='email'><strong>Email</strong></label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>' class="contact_input shadow"> </p> <p> <label for='telephone'><strong>Telephone</strong></label><br> <input type="text" name="telephone" value='<?php echo htmlentities($visitor_telephone) ?>' class="contact_input shadow"> </p> <p> <label for='hear'><strong>How did you hear about us?</strong></label><br> <input type="text" name="hear" value='<?php echo htmlentities($visitor_hear) ?>' class="contact_input shadow"> </p> <p> <label for='subject'><strong>Subject</strong></label><br> <input type="text" name="subject" value='<?php echo htmlentities($visitor_subject) ?>' class="contact_input shadow"> </p> <p> <label for='message'><strong>Message</strong></label> <br> <textarea name="message" rows=8 cols=35 style="border:none;width:310px;" class="shadow"><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="script/captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br /> <label for='message'>Enter the code above here:</label><br> <input id="6_letters_code" name="6_letters_code" type="text" style="border:none;" class="shadow"><br /> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit' class="rapidcharge-contact-btn"> </form> <script> var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("department","req","You forgot to choose a department!"); frmvalidator.addValidation("name","req","You forgot to enter your name!"); frmvalidator.addValidation("email","req","You forgot to enter your email!"); frmvalidator.addValidation("subject","req","You forgot to enter a subject!"); frmvalidator.addValidation("hear","req","How did you hear about us?"); frmvalidator.addValidation("message","req","No message? hrmph!"); </script> <script> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script>
  4. this is what i have now. it works to an extent. it will send the message but also display 'invalid department' at the same time, thoughts? http://getrapidcharge.com/rcsite/contact.php <?php session_start(); $errors = ''; $name = ''; $visitor_email = ''; $visitor_telephone = ''; $visitor_subject = ''; $visitor_hear = ''; $user_message = ''; $your_email = ''; $department = ''; $contactAry = array( 'Sales' => 'mail1@getrapidcharge.com', 'Advertising' => 'mail2@getrapidcharge.com', ); if(isset($_POST['submit'])) { if(!array_key_exists($_POST['department'], $contactAry)) { $invaliddept = ''; $invaliddept .= "<p class='fail' align='center'>Invalid department</p>"; } else { $your_email = $contactAry[$_POST['department']]; } $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_telephone = $_POST['telephone']; $visitor_subject = $_POST['subject']; $visitor_hear = $_POST['hear']; $user_message = $_POST['message']; $your_email = $_POST['department']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n<div class='captcha-miss'>Please Fill out Required Fields.</div>"; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email entry!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n <div class='captcha-miss'>The captcha code does not match!</div>"; } if(empty($errors)) { //send the email $to = $your_email; $subject="Form Submission From Contact Page"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "$name submitted the contact form for $department:\n". "Name: $name\n". "Email: $visitor_email \n". "Telephone: $visitor_telephone \n\n". "How did you hear about us? $visitor_hear \n\n". "Subject: $visitor_subject \n\n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); $success = ''; $success .= "<p class='success' align='center'>Your message sent!</p>"; } } // 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; } } ?> <?php echo $success; ?> <?php echo $invaliddept; ?> <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='department'><strong>Department</strong></label><br> <select name="department"> <option>Select Department...</option> <?php foreach($contactAry as $department => $your_email) { echo "<option value='$department'>$department</option>\n"; } ?> </select> </p> <p> <label for='name'><strong>Name</strong></label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>' class="contact_input shadow"> </p> <p> <label for='email'><strong>Email</strong></label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>' class="contact_input shadow"> </p> <p> <label for='telephone'><strong>Telephone</strong></label><br> <input type="text" name="telephone" value='<?php echo htmlentities($visitor_telephone) ?>' class="contact_input shadow"> </p> <p> <label for='hear'><strong>How did you hear about us?</strong></label><br> <input type="text" name="hear" value='<?php echo htmlentities($visitor_hear) ?>' class="contact_input shadow"> </p> <p> <label for='subject'><strong>Subject</strong></label><br> <input type="text" name="subject" value='<?php echo htmlentities($visitor_subject) ?>' class="contact_input shadow"> </p> <p> <label for='message'><strong>Message</strong></label> <br> <textarea name="message" rows=8 cols=35 style="border:none;width:310px;" class="shadow"><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="script/captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br /> <label for='message'>Enter the code above here:</label><br> <input id="6_letters_code" name="6_letters_code" type="text" style="border:none;" class="shadow"><br /> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit' class="rapidcharge-contact-btn"> </form> <script type="text/javascript"> var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("department","req","You forgot to choose a department!"); frmvalidator.addValidation("name","req","You forgot to enter your name!"); frmvalidator.addValidation("email","req","You forgot to enter your email!"); frmvalidator.addValidation("subject","req","You forgot to enter a subject!"); frmvalidator.addValidation("hear","req","How did you hear about us?"); frmvalidator.addValidation("message","req","No message? hrmph!"); </script> <script type="text/javascript"> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script>
  5. wrong button. please remove.
  6. i assumed that could be the problem. now it just pushes down my headers and display text outside of the select. http://getrapidcharge.com/rcsite/contact.php
  7. i've implemented this using the forms processing variable of $your_email, but i get this error: Warning: Invalid argument supplied for foreach(). Thoughts? if(isset($_POST['submit'])) { $contactAry = array( 'Sales' => 'matthew@gmail.com', 'Advertising' => 'matthew@gmail.com', ); if(!array_key_exists($_POST['department'], $contactAry)) { echo "Invalid department"; } else { $your_email = $contactAry[$_POST['department']]; } .... <select name="destemail"> <?php echo "<select name='department'>\n"; foreach($contactAry as $department => $your_email) { echo "<option value='$department'>$department</option>\n"; } echo "</select>\n"; ?> </select>
  8. hey guys, if you goto getrapidcharge.com/rcsite/contact.php, i've implemented a contact form. i'dd like to add a field to the top where i can choose a department from a dropdown list, which in turn will send the email to the selected departments address. This is currently whats processing the form. any help would be greatly appreciated. i thought about an array but im not sure how i'd implement it. <?php session_start(); $errors = ''; $name = ''; $visitor_email = ''; $visitor_telephone = ''; $visitor_subject = ''; $visitor_hear = ''; $user_message = ''; $your_email ='admin@getrapidcharge.com';// <<=== update to your email address if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_telephone = $_POST['telephone']; $visitor_subject = $_POST['subject']; $visitor_hear = $_POST['hear']; $user_message = $_POST['message']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Please Fill out Required Fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email entry!"; } if(empty($_SESSION['6_letters_code'] ) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) { //Note: the captcha code is compared case insensitively. //if you want case sensitive match, update the check above to // strcmp() $errors .= "\n <div class='captcha-miss'>The captcha code does not match!</div>"; } if(empty($errors)) { //send the email $to = $your_email; $subject="Form Submission From Contact Page"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Name: $name\n". "Email: $visitor_email \n". "Telephone: $visitor_telephone \n". "Subject: $visitor_subject \n". "How did you hear about us? $visitor_hear \n". "Message: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); $success = ''; $success .= 'Your message sent!'; //header('Location: contact.php'); } } // 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; } } ?> heres the HTML/JS <?php if(!empty($errors)){ echo "<p class='err'>".nl2br($errors)."</p>"; } ?> <div id='contact_form_errorloc' class='err'></div> <form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <p> <label for='name'><strong>Name</strong></label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>' class="contact_input"> </p> <p> <label for='email'><strong>Email</strong></label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>' class="contact_input"> </p> <p> <label for='telephone'><strong>Telephone</strong></label><br> <input type="text" name="telephone" value='<?php echo htmlentities($visitor_telephone) ?>' class="contact_input"> </p> <p> <label for='subject'><strong>Subject</strong></label><br> <input type="text" name="subject" value='<?php echo htmlentities($visitor_subject) ?>' class="contact_input"> </p> <p> <label for='hear'><strong>How did you hear about us?</strong></label><br> <input type="text" name="hear" value='<?php echo htmlentities($visitor_hear) ?>' class="contact_input"> </p> <p> <label for='message'><strong>Message</strong></label> <br> <textarea name="message" rows=8 cols=30 style="border:none;"><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="script/captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br /> <label for='message'>Enter the code above here :</label><br> <input id="6_letters_code" name="6_letters_code" type="text" style="border:none;"><br /> <small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small> </p> <input type="submit" value="Submit" name='submit' class="rapidcharge-contact-btn"> </form> <script type="text/javascript"> var frmvalidator = new Validator("contact_form"); //remove the following two lines if you like error message box popups frmvalidator.EnableOnPageErrorDisplaySingleBox(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","You forgot to enter your name!"); frmvalidator.addValidation("email","req","You forgot to enter your email!"); frmvalidator.addValidation("email","email","Please enter a valid email address"); frmvalidator.addValidation("subject","req","You forgot to enter a subject!"); frmvalidator.addValidation("hear","req","How did you hear about us?"); frmvalidator.addValidation("message","req","No message? hrmph!"); </script> <script type="text/javascript"> function refreshCaptcha() { var img = document.images['captchaimg']; img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000; } </script>
  9. hey guys, Right now i'm using a ridiculous amount of jquery to display promos on my search result pages. each product is wrapped with numerous DIVs to allow this to happen. I'm not really a php pro but i can usually get by. Im looking for suggestions for a way i could accomplish something similar with php just to make the site load a little bit faster while still being able to merchandize. i.e. right now i have a 10/15/20% promo going on. each product has a 10div 15div 20div all hidden, then i give my on sale products the keyword promo10, promo15, promo20 and use css to display the promo that has a bit of JS math in there to display the correct promo price. i also have some jquery that appends a 'promo' div each search result is wrapped with, that way i can display promo text under the result image. there are so many things going on it slows the site down so im looking for way to use PHP to display the promos rather than append with jquery. any ideas will be greatly appreciated.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.