Jump to content

deziner76hd

Members
  • Posts

    25
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

deziner76hd's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. And with the above commented out i still get this printed on the page Index: 0 - Value: first Index: 1 - Value: second Index: 2 - Value: third Warning: Cannot modify header information - headers already sent by (output started at /home/richardi/public_html/test2.php:33) in /home/richardi/public_html/test2.php on line 93
  2. Ok I commented out: if( $_POST['submitted'] == 'yes') { echo '<pre>'; print_r($_POST); echo '</pre><br>'; And All I can get it to print to email is: Array Why?
  3. Well I am trying to learn and understand all this. I start to think I have things under control and when I try what I think will work (several variations) and it doesn't it's gets a little frustrating. This is what is returned A user Gary T White submitted the contact form: (working) Full Name: Gary T White (working) Email: test@tesitnmf.com (working) Gender: female (working) Languages I Speak: English (not working) Preferred Language: English (working) Favorite color: Array (not working) Education: HighSchool (working) Check Boxes: Array (not working) Q1: the ands Message: xcghnfcg IP: 74.74.118.219 Above Head <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; $language = $_POST['lang']; $Preferred = $_POST['preflang']; $color = $_POST['color']; $education = $_POST['education']; $boxes = $_POST['boxes']; ///------------checkbox------------- if( $_POST['submitted'] == 'yes') { echo '<pre>'; print_r($_POST); echo '</pre><br>'; if( is_array($_POST['boxes']) ) { foreach( $_POST['boxes'] as $key => $value ) { echo "Index: $key - Value: $value<br>"; } } } ///// collecting form data color ///// @$color= $_POST['color']; if( is_array($color)){ while (list ($key, $val) = each ($color)) { ////---echo "$val <br>"; } }//else{echo "not array";} ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } 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 The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Languages I Speak: $lang \n". "Preferred Language: $preflang \n". "Favorite color: $color \n". "Education: $education \n". "Check Boxes: $boxes \n". "Q1: $visitor_q1 \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); header('Location: thank-you.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; } } ?> Form <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST" name="contact_form" class="style25"> <p> <label for='name'>Full Name: </label><br> <input type="text" name="name" value='<?php echo htmlentities($name) ?>'> </p> <p> <label for='email'>Email: </label><br> <input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'> <p> <p> <label for='q1'>Q1: </label><br> <input type="text" name="q1" value='<?php echo htmlentities($visitor_q1) ?>'> <p>My gender is: <p> <input type="radio" name="gender" value="male" <?php echo $_POST['gender'] == 'male' ? 'selected="selected"' : ''; ?>/> <label for='gender'>Male: </label> <br /> <input type="radio" name="gender" value="female" <?php echo $_POST['gender'] == 'female' ? 'selected="selected"' : ''; ?>/> <label for='Gender'>Female:</label> <br /><br /> <label for='boxes'>Checkboxes:</label><br /><br /> First: <input type="checkbox" name="boxes[]" value="first" <?php echo (is_array($_POST['boxes']) && in_array('first', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>><br> Second: <input type="checkbox" name="boxes[]" value="second" <?php echo (is_array($_POST['boxes']) && in_array('second', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>><br> Third: <input type="checkbox" name="boxes[]" value="third" <?php echo (is_array($_POST['boxes']) && in_array('third', $_POST['boxes'])) ? 'checked = "checked"' : ''; ?>><br> <br /><br />Select a Level of Education:<br /><br /> <select name="education"> <option value="Jr.High">Jr.High</option> <option value="HighSchool">HighSchool</option> <option value="College">College</option></select>:<br /><br /> Select your favorite time of day::<br /><br /> <select name="TofD" size="3"> <option value="Morning">Morning</option> <option value="Day">Day</option> <option value="Night">Night</option></select>:<br /><br /> Select your favorite color::<br /><br /> <select name='color[]' size=4 multiple> <option value='blue'>Blue</option> <option value='green'>Green</option> <option value='red'>Red</option> <option value='yellow'>Yelllow</option> <option value='' selected>Select a Color </option> <option value='white'>White</option> </select> <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value="English" <?php echo $_POST['lang'] == 'en' ? 'selected="selected"' : ''; ?>/> English<br /> <input type="checkbox" name="lang" value="Français" <?php echo $_POST['lang'] == 'fr' ? 'selected="selected"' : ''; ?>/> Français<br /> <input type="checkbox" name="lang" value="Español" <?php echo $_POST['lang'] == 'es' ? 'selected="selected"' : ''; ?>/> Español<br /> </p> <p>My preferred language is: </p> <input type="radio" name="preflang" value="English" <?php echo $_POST['preflang'] == 'en' ? 'selected="selected"' : ''; ?>/> <label for='Preferred'>English: </label> <br /> <input type="radio" name="preflang" value="Français" <?php echo $_POST['preflang'] == 'fr' ? 'selected="selected"' : ''; ?>/> <label for='Preferred'>Français:</label> <br /> <input type="radio" name="preflang" value="Español" <?php echo $_POST['preflang'] == 'es' ? 'selected="selected"' : ''; ?>/> <label for='Preferred'>Español:</label> <p> <label for='message'>Message:</label> <br> <textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea> </p> <p> <img src="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"><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'> </form>
  4. Ok I see how this all works but I still can't get it to print to e-mail
  5. Yes The last explanation of how it is all put together actually clicked and gave me insight into how it all works. Now I will try to implement it into my existing form and get it to work. Thank you
  6. Did you notice it's 1:00am again? it seems like I am always up at 1:00 am working on something. I want you to know I really do appreciate all the time you have put in helping me.
  7. If I include it in a form and print to email it sends a return of Array A user gary submitted the contact form: Full Name: gary Email: gwhite@dezinezone2002.com Gender: male Languages I Speak: English Preferred Language: en All Boxex: Array Q1: an answer Message: ukg IP: 74.74.118.219
  8. Thank you can you tell me why it prints this above the answers it prints? Array ( [boxes] => Array ( [0] => first [1] => second ) [submitted] => yes [submit] => Submit ) This is what it prints in entirety. Array ( [boxes] => Array ( [0] => first [1] => second [2] => third ) [submitted] => yes [submit] => Submit ) Index: 0 - Value: first Index: 1 - Value: second Index: 2 - Value: third First: Second: Third: I would think it should just print this with all three checked Index: 0 - Value: first Index: 1 - Value: second Index: 2 - Value: third
  9. Am I headed in the correct direction? <?php echo $_POST[$lang[]] = "English" ? 'selected="selected"' : ''; ?>/ $lang[] = "Français"; $lang[] = "Español";
  10. Ok Here is my array $lang[] = "English"; $lang[] = "Français"; $lang[] = "Español";
  11. I am not familiar with how I would write an array. Could you show me what I need to do or point me in the direction of a good tutorial?
  12. Ok When I choose all 3 English French and Spanish it only returns Spanish I t only returns the last one I choose. Can anyone see where I am missing something to make it choose all the check boxes and print them? Thank you for your help Result A user gary submitted the contact form: Full Name: gary Email: gwhite@dezinezone2002.com Gender: male Language: es Q1: an answer Message: fdsd IP: 74.74.118.219 Above header <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; $language = $_POST['lang']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } 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 The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Language: $lang \n". "Q1: $visitor_q1 \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); header('Location: thank-you.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; } } ?> In form <p>I speak the following languages: </p> <p> <input type="checkbox" name="lang" value="en" <?php echo $_POST['lang'] == 'en' ? 'selected="selected"' : ''; ?>/> English<br /> <input type="checkbox" name="lang" value="fr" <?php echo $_POST['lang'] == 'fr' ? 'selected="selected"' : ''; ?>/> Français<br /> <input type="checkbox" name="lang" value="es" <?php echo $_POST['lang'] == 'es' ? 'selected="selected"' : ''; ?>/> Español<br /> </p>
  13. Radio buttons work great! I'm starting to understand somewhat how this works. I have a 100 hours in something that should take a couple but hopefully I will retain the basic concepts. I tried to incorporate the same code into check boxes but it didn't work. Should it work and I just have something small wrong in the syntax or is it an entirely different type of code I should be using for check boxes? Above head <?php $your_email ='gwhite@dezinezone2002.com';// <<=== update to your email address session_start(); $errors = ''; $name = ''; $visitor_email = ''; $user_message = ''; if(isset($_POST['submit'])) { $name = $_POST['name']; $visitor_email = $_POST['email']; $visitor_q1 = $_POST['q1']; $user_message = $_POST['message']; $gender = $_POST['gender']; $language = $_POST['lang']; ///------------Do Validations------------- if(empty($name)||empty($visitor_email)) { $errors .= "\n Name and Email are required fields. "; } if(IsInjected($visitor_email)) { $errors .= "\n Bad email value!"; } 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 The captcha code does not match!"; } if(empty($errors)) { //send the email $to = $your_email; $subject="New form submission"; $from = $your_email; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name submitted the contact form:\n". "Full Name: $name\n". "Email: $visitor_email \n". "Gender: $gender \n". "Language: $lang \n". "Q1: $visitor_q1 \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); header('Location: thank-you.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; } } ?> In Form <p> <input type="checkbox" name="language" value="en" <?php echo $_POST['lang'] == 'en' ? 'selected="selected"' : ''; ?>/> English<br /> <input type="checkbox" name="language" value="fr" <?php echo $_POST['lang'] == 'fr' ? 'selected="selected"' : ''; ?>/> Français<br /> <input type="checkbox" name="language" value="es" <?php echo $_POST['lang'] == 'es' ? 'selected="selected"' : ''; ?>/> Español<br /> </p>
×
×
  • 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.