Jump to content

kcelsi

Members
  • Posts

    29
  • Joined

  • Last visited

kcelsi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm afraid that my desired answer to you is not appropriate to post in a forum so I'll offer the subdued version. Why don't you stick to writing your own code and stay out of volunteer jobs designed to help people. You are obviously not cut out for it and your pompous attitude could use some checking. I'm sorry I wasted so many minutes of my day even discussing this with you.
  2. Isn't that what you are supposed to do? Help beginners with php? All I want to do is find out how to validate a phone number in a certain format. After all of this, you still haven't suggested to me one line of code that could accomplish that. Why are you judging the method that I use to learn? If someone else writes good code, why can't I use it for my own projects? How can I start to write my own code, if I don't learn from seeing other examples first?
  3. I understand about good posting and I only want to put up what is useful. The problem with learning programming is that there's so much code whether in the head, body, external files, etc that I have a hard time figuring out what is relevant. If you had instructed me about which part I should have used, then in future posts I would have known what to do. There's a big learning curve here. In my opinion, you should have taken a little extra time to read the code I posted this time, answered my question with some suggested solutions and then stated that in future posts, I should try not to put in things that are not necessary if possible. It just would have been a nice courtesy. Sorry, I'm just frustrated that I haven't figured this out yet.
  4. I have found a beginner php forum that will answer my questions without getting annoyed. Sorry to have bothered you.
  5. It's difficult for me to dig out exactly which parts need to be changed, but I'm guessing that I have to modify one of these to pertain to phone instead of email...and maybe set a $phone variable??? 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)); }
  6. One more question about this... How can I edit this code so that the phone number field will only be validated if it is in the form of "000-000-0000"? <?php // Set email variables $email_to = 'kcelsi@littlechisel.com'; $email_subject = 'Form submission'; // Set required fields $required_fields = array('fullname','phone','email','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'phone' => 'Please enter a Phone Number to proceed.', 'email' => 'Please enter a valid Email Address to continue.', 'comment' => 'Please enter your Message to continue.' ); // 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)); } ?>
  7. I figured out the problem. There was an external php include that I forgot to update. The field is validating fine now. Thanks for your help and patience.
  8. I need to have the field display an error if the field is not filled out. If you go to the link I included, you will see that if you hit Send Message without filling in the form, the name, email and message fields will display the error, but not the phone field. Please be patient with me. I really need to learn this.
  9. Yes, I've looked at the code thoroughly and I'm trying to decipher it. I thought this part did the validation: if (phone.get('value').length === 0) { isValid = false; addError(phone, phoneError); } else { isValid = true; removeError(phone); }
  10. Sorry, I'm new to php and am learning as I go. Can you tell me exactly which part you need? I'm not sure what "attempt at validation" means.
  11. Hello, I'm creating a form using code I obtained from an online tutorial. It works perfectly and validates as it should. I would like to add a "phone" field which would also need validation. So far I have not been able to get the field to validate. What am I missing?? I've included the parts of the php that I changed and also attached my javascript validation file as a text file. Here is a link to the page the form is on: http://www.idealwindow.com/Contact_Marketing.php Thanks for any help you can offer. In the head tag: <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="js/validation.js"></script> <script type="text/javascript"> var nameError = '<?php echo $error_messages['fullname']; ?>'; var phoneError = '<?php echo $error_messages['phone']; ?>'; var emailError = '<?php echo $error_messages['email']; ?>'; var commentError = '<?php echo $error_messages['comment']; ?>'; 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.indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}} } </script> In the body tag: <div class="row"> <div class="label">Full 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 or Jane Doe</div><!-- end .context --> </div><!-- end .row --> <div class="row"> <div class="label">Phone</div><!-- end .label --> <div class="input"> <input type="text" id="phone" class="detail" 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">e.g. 000-000-0000</div><!-- end .context --> </div><!-- end .row --> validation.txt
  12. Sorry, I have since scrapped this code. I found it from a website tutorial that was outdated and too complicated. I've found an amazing php form tutorial here: http://www.dreamweavertutorial.co.uk/dreamweaver/video/contact-form-php-validation.htm an I'm using that as my base form now. Thanks for your input.
  13. Hello, I obtained this code for a php form including a Captcha that I have modified. My question is, how do I make a field "not required", but if filled out, the entry will also be sent with the form? I'm planning to add fields for fax, address, etc that won't be necessary, but helpful if entered. Thank you. Here is my code: <?php if(isset($_POST['submitted'])) { require_once('captcha/recaptchalib.php'); $privatekey = "6Ldke-wSAAAAAPrYCfs4gR28Y10hEttom0ax-nKD"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if(trim($_POST['checking']) !== '') { $blindError = true; } else { $authorName = (filter_var($_POST['formAuthor'], FILTER_SANITIZE_STRING)); if ($authorName == ""){ $authorError = true; $hasError = true; }else{ $formAuthor = $authorName; }; $authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL)); if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){ $emailError = true; $hasError = true; } else{ $formEmail = $authorEmail; }; $msgSubject = (filter_var($_POST['formSubject'], FILTER_SANITIZE_STRING)); if ($msgSubject == ""){ $subjectError = true; $hasError = true; }else{ $formSubject = $msgSubject; }; //Check to make sure content has been entered $msgContent = (filter_var($_POST['formContent'], FILTER_SANITIZE_STRING)); if ($msgContent == ""){ $commentError = true; $hasError = true; }else{ $formContent = $msgContent; }; if (($resp->is_valid) && (!isset($hasError))) { $emailTo = 'kcelsi@littlechisel.com'; // here you must enter the email address you want the email sent to $subject = 'Marketing Inquiry From: ' . $formAuthor . ' | ' . $formSubject; // This is how the subject of the email will look like $body = "Email: $formEmail \n\nContent: $formContent \n\n$formAuthor"; // This is the body of the email $headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers mail($emailTo, $subject, $body, $headers); $emailSent = true; } if (!($resp->is_valid)){ $captchaErrorMsg = true; } } } ?> <?php // if the page the variable "email sent" is set to true show confirmation instead of the form ?> <?php if(isset($emailSent) && $emailSent == true) { ?> <style type="text/css"> #wrapper { width: 960px; margin-right: auto; margin-left: auto; } #content { font-family: Verdana, Geneva, sans-serif; text-align: center; } .thankyou { font-size: 24px; font-weight: bold; } .text { margin-top: -5px; padding-top: 0px; font-size: 16px; } a { color: #900; text-decoration: none; font-size: 14px; } </style> </head> <body> <div id="wrapper"> <div id="content"> <p class="thankyou">Thank You</p> <p class="text">Your form has been submitted and someone from Ideal Window will contact you shortly.</p> <a href="http://www.idealwindow.com/">Back to Ideal Window Home Page</a> </div> </div> <?php } else { ?> <?php // if there are errors in the form show a message ?> <?php if(isset($hasError) || isset($blindError)) { ?> <p>There was an error submitting the form. Please check all the marked fields.</p> <?php } ?> <?php // if there are recaptcha errors show a message ?> <?php if ($captchaErrorMsg){ ?> <p>Captcha error. Please, type the check-words again.</p> <?php } ?> <?php ?> <script type="text/javascript"> var RecaptchaOptions = { theme : 'clean' }; </script> <?php ?> <form id="contactForm" action="" method="post"> <div id="singleParagraphInputs"> <div> <label for="formAuthor"> Full Name </label> <input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>" size="40" /> </div> <div> <label for="formEmail"> Email </label> <input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="40" /> </div> <div> <label for="formSubject"> Subject </label> <input class="requiredField <?php if($subjectError) { echo 'formError'; } ?>" type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="40" /> </div> </div> <div id="commentTxt"> <label for="formContent"> Message </label> <textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="40" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea> <?php ?> <div id="screenReader"> <label for="checking"> If you want to submit this form, do not enter anything in this field </label> <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /> </div> </div> <?php require_once('captcha/recaptchalib.php'); $publickey = "6Ldke-wSAAAAAE7yRt4cUb3G6hYU__6JIwsc6lwL"; echo recaptcha_get_html($publickey); ?> <input type="hidden" name="submitted" id="submitted" value="true" /> <?php // submit button ?> <input type="submit" value="Send Message" tabindex="5" id="submit" name="submit"> </form> <?php } // yay! that's all folks! ?> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.js"> </script> <script src="js/custom.js" type="text/javascript"> </script> CSS: body{ font: 14px/1.5em sans-serif; margin: 0; padding: 0; } label { display: block; padding: 1px 7px 0; position: absolute; top: 0; z-index: 1; } input[type=text], textarea { display: block; background: none; font: inherit; padding: 0 7px; position: relative; z-index: 10; overflow: auto; } label, input[type=text], #singleParagraphInputs div{ line-height: 1.5em; height: 1.5em; } #singleParagraphInputs div, #commentTxt, #recaptcha_widget_div{ margin-bottom: 1.5em; } input, textarea, #recaptcha_table{ border: 1px solid #ccc; } .formError { border: 1px solid red; } #contactForm, #recaptcha_table{ width: 600px; margin: 0 auto; margin-top: 50px; } #singleParagraphInputs div, #commentTxt { position: relative; } #singleParagraphInputs input { width: 584px; /* 16px less than form width } #commentTxt textarea { min-height: 9em; min-width: 584px; /* 16px less than form width font: 14px/1.5em sans-seif; } #screenReader, #checking { float: left; display: none; } #recaptcha_response_field { width: 286px !important; } input[type=submit]{ } javascript: $(function(){ $formItems = $("input:text, textarea"); $formItems // fires after the page has loaded // if the field has already some value the label becomes invisible .each(function(){ if ($(this).val() !== '') { $(this).prev().css({ opacity: '0' }); }; }) .focus(function(){ if ($(this).val() == '') { $(this).prev().stop().animate({ opacity: '0' }, 200); } }) .blur(function(){ if ($(this).val() == '') { $(this).prev().stop().animate({ opacity: '1' }, 200); } }) });
  14. I found this possible explanation here: http://stackoverflow.com/questions/8028957/headers-already-sent-by-php To understand why headers must be sent before output it's necessary to look at a typical HTTP*response. PHP scripts mainly generate HTML content, but also pass a set of HTTP/CGI headers to the webserver: HTTP/1.1 200 OK Powered-By: PHP/5.3.7 Vary: Accept-Encoding Content-Type: text/html; charset=utf-8 <html><head><title>PHP page output page</title></head> <body><h1>Content</h1> <p>Some more output follows...</p> and <a href="/"> <img src=about:note> ... The page/output always follows the headers. PHP is required to pass the headers to the webserver first. It can only do that once. And after the double linebreak it can't ever append to them again. When PHP receives the first output (print, echo, <html>) it will "flush" the collected headers. Afterwards it can send all the output bits it wants. But sending further headers is impossible from then. How can you find out where the premature output occured?The header() warning contains all relevant information to locate the problem source: Here "line 100" refers to the script where the header() invocation failed. Warning: Cannot modify header information - headers already sent by (output started at/www/usr2345/htdocs/auth.php:52) in /www/usr2345/htdocs/index.php on line 100 The message in the inner parenthesis is more crucial. It mentions auth.php and line 52 as the source of premature output. One of the typical problem causes will be there: Print, echoIntentional output from print and echo statements will terminate the opportunity to send HTTP headers. The application flow must be restructured to avoid that. Use functions and templating schemes. Ensure header() calls occur before messages are written out. Functions that can write output include print, echo, printf, trigger_error, vprintf,ob_flush, var_dump, readfile, passthru among others and user-defined functions. My code: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="Marketing_Contact" id="Marketing_Contact"> FORM HTML <?php ob_start(); require_once('recaptchalib.php'); // Get a key from http://recaptcha.net/api/getkey $publickey = "6Ldke-wSAAAAAE7yRt4cUb3G6hYU__6JIwsc6lwL"; $privatekey = "6Ldke-wSAAAAAPrYCfs4gR28Y10hEttom0ax-nKD"; # the response from reCAPTCHA $resp = null; # the error code from reCAPTCHA, if any $error = null; # was there a reCAPTCHA response? if ($_POST["recaptcha_response_field"]) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($resp->is_valid) { $company = $_POST['company']; $fullname = $_POST['fullname']; $address = $_POST['address']; $address2 = $_POST['address2']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $phone = $_POST['phone']; $fax = $_POST['fax']; $email = $_POST['email']; $category = $_POST['category']; $message = $_POST['message']; $subject = "Marketing Inquiry"; $company = stripslashes($company); $fullname = stripslashes($fullname); $address = stripslashes($address); $city = stripslashes($city); $state = stripslashes($state); $zip = stripslashes($zip); $phone = stripslashes($phone); $fax = stripslashes($fax); $email = stripslashes($email); $category = stripslashes($category); $message = stripslashes($message); $subject = stripslashes($subject); $final_message = "You have a marketing inquiry\n\n"; $final_message .= "From: " . $fullname . "\n"; $final_message .= "Address: " . $address . "\n"; $final_message .= "Address 2: " . $address2 . "\n"; $final_message .= "City: " . $city . "\n"; $final_message .= "State: " . $state . "\n"; $final_message .= "Zip Code: " . $zip . "\n"; $final_message .= "Phone: " . $phone . "\n"; $final_message .= "Fax: " . $fax . "\n"; $final_message .= "Email: " . $email . "\n"; $final_message .= "Category: " . $category . "\n"; $final_message .= "Message: " . $message . "\n"; mail("graphics_Beth@idealwindow.com", 'Online Form: '.$subject, $_SERVER['REMOTE_ADDR']."\n\n".$final_message, "From: ".$fullname); exit(header('location:http://www.idealwindow.com/Thank_You.html')); } else { # set the error code so that we can display it $error = $resp->error; echo $error; } } echo recaptcha_get_html($publickey, $error); ?><input type="submit" name="Submit" id="Submit" /></form> Here is the error message: Warning: Cannot modify header information - headers already sent by (output started at /home/ideal/public_html/Contact_Marketing.php:160) in/home/ideal/public_html/Contact_Marketing.php on line 303 The red highlighted lines are 160 and 303. Can anyone explain how I can modify these lines to prevent the error?
  15. Thank you. This does work, but the issue I have is that it appears at the bottom of the page. So after the form is submitted, the top of the same page shows up and it appears that nothing has happened and you have to scroll down. I like it better when a new page comes up with the message at the top so there's no scrolling necessary to see the result. If anyone knows another way to redirect to a new page, please let me know.
×
×
  • 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.