jarvis
Members-
Posts
543 -
Joined
-
Last visited
Everything posted by jarvis
-
Hi All, The following code is an include on my site. What I'm after is a redirect, using headers is the best & quickest method, however, whenever I try this, I get the damned headers sent message. Is this because it's an include file? here's my code: <?php require_once "/lib/viewer_functions.php"; // process form if (@$_REQUEST['submitForm']) { // error checking $errorsAndAlerts = ""; $check = $_REQUEST['check']; $randomNumber = $_REQUEST['randomNumber']; if (!@$_REQUEST['name']) { $errorsAndAlerts = "Please add your name\n"; } if (!@$_REQUEST['email']) { $errorsAndAlerts = "Please add your email\n"; } else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "That email address is not valid\n"; } if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please add your enquiry\n"; } if (!@$_REQUEST['randomNumber']) { $errorsAndAlerts = "Please verify the number\n"; } $textToConvert = $_REQUEST['enquiry']; $convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert); // send email user if ((!$errorsAndAlerts) && ($randomNumber == $check)) { $to = "[email protected]"; $subject = "Quick Contact"; $email = "[email protected]"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: $email \r\n"; $body = "<strong>Full name</strong>: ". $_REQUEST['name'] ."<br />"; $body .= "<strong>Email</strong>: ".$_REQUEST['email'] ."<br />"; $body .= "<strong>Enquiry</strong>: $convertedText<br /><br />"; $body .= "The user who sent this message had the IP address <strong>".$_SERVER['REMOTE_ADDR']."</strong><br />"; $message = $body; // send message $mailResult = @mail($to, $subject, $message, $headers); if (!$mailResult) { die("Mail Error: $php_errormsg"); } // //$errorsAndAlerts = "Thanks! We've sent your email."; header("Location: /thanks.php"); exit(); $_REQUEST = array(); // clear form values } } ?> <?php $randomNumber = rand(1,10); ?> <!-- right quick_contact form --> <!-- quick_contact_title --> <div class="rh_quick_contact_title"> <img src="images/rh_quick_enquiry_title.jpg" width="232" height="31" /> </div> <!-- /quick_contact_title --> <!-- quick_contact_form --> <div class="rh_quick_contact_content_larger"> <form method="post"> <input type="hidden" name="submitForm" value="1" /> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td align="center"> <input name="name" type="text" id="name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" /> </td> </tr> <tr> <td align="center"> <input name="email" type="text" id="email" style="width:180px;" value="Email Address..." onclick="clickclear(this, 'Email Address...')" onblur="clickrecall(this,'Email Address...')"/> </td> </tr> <tr> <td align="center"> <textarea name="enquiry" id="enquiry" value="Enquiry..." onclick="clickclear(this, 'Enquiry...')" onblur="clickrecall(this,'Enquiry...')" style="width:180px;" rows="3"></textarea> </td> </tr> <tr> <td align="center"><input type="text" id="randomNumber" name="randomNumber" style="width:20px;" /> Please enter the following number in the left hand box: <?php echo $randomNumber; ?> </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit"> </div></td> </tr> </table> <input type="hidden" id="check" name="check" value="<?php echo $randomNumber;?>" /> </form> </div> <!-- /quick_contact_form --> As always, any help is much appreciated! Thanks
-
Hi roopurt18 I'll alter those now. It's code i've inherited, I'm just adding to it. is there anyway I can redirect the user after the form is complete with correct info? Can only think of header() but the above is an include on a page so gives the headers sent error Thanks
-
Thanks all, I think I've now got it working. Albeit an undefined warning message. Here's my final code: if (@$_REQUEST['submitForm']) { // error checking $errorsAndAlerts = ""; $check = $_REQUEST['check']; $randomNumber = $_REQUEST['randomNumber']; if (!@$_REQUEST['name']) { $errorsAndAlerts = "Please add your name\n"; } if (!@$_REQUEST['email']) { $errorsAndAlerts = "Please add your email\n"; } else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "That email address is not valid\n"; } if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please add your enquiry\n"; } if (!@$_REQUEST['randomNumber']) { $errorsAndAlerts = "Please verify the number\n"; } $textToConvert = $_REQUEST['enquiry']; $convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert); // send email user if ((!$errorsAndAlerts) && ($randomNumber == $check)) { $to = "[email protected]"; $subject = "Quick Contact"; $email = $_REQUEST['email']; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; #$headers .= "Content-Type: text/html; charset=utf8\r\n"; $headers .= "From: $email \r\n"; $body = "<strong>Full name</strong>: ". $_REQUEST['name'] ."<br />"; $body .= "<strong>Email</strong>: ".$_REQUEST['email'] ."<br />"; $body .= "<strong>Enquiry</strong>: $convertedText<br /><br />"; $body .= "The user who sent this message had the IP address <strong>".$_SERVER['REMOTE_ADDR']."</strong><br />"; $message = $body; // send message $mailResult = @mail($to, $subject, $message, $headers); if (!$mailResult) { die("Mail Error: $php_errormsg"); } // $errorsAndAlerts = "Thanks! We've sent your email."; $_REQUEST = array(); // clear form values } } ?> <?php $randomNumber = rand(1,10); ?> <!-- right quick_contact form --> <!-- quick_contact_title --> <div class="rh_quick_contact_title"> <img src="images/rh_quick_enquiry_title.jpg" width="232" height="31" /> </div> <!-- /quick_contact_title --> <!-- quick_contact_form --> <div class="rh_quick_contact_content"> <form method="post"> <input type="hidden" name="submitForm" value="1" /> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td align="center"> <input name="name" type="text" id="name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" /> </td> </tr> <tr> <td align="center"> <input name="email" type="text" id="email" style="width:180px;" value="Email Address..." onclick="clickclear(this, 'Email Address...')" onblur="clickrecall(this,'Email Address...')"/> </td> </tr> <tr> <td align="center"> <textarea name="enquiry" id="enquiry" value="Enquiry..." onclick="clickclear(this, 'Enquiry...')" onblur="clickrecall(this,'Enquiry...')" style="width:180px;" rows="3"></textarea> </td> </tr> <tr> <td><?php echo $randomNumber; ?> <input type="text" id="randomNumber" name="randomNumber" style="width:20px;" /> Please enter the number </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit"> </div></td> </tr> </table> <input type="hidden" id="check" name="check" value="<?php echo $randomNumber;?>" /> </form> Thank you all for your help. I think that's everything I need!?!?!
-
I'd like to try this without sessions but think I've not grasped meltingpoint's method <?php // process form if (@$_REQUEST['submitForm']) { // error checking $errorsAndAlerts = ""; if (!@$_REQUEST['quick_enquiry_name']) { $errorsAndAlerts = "No name\n"; } if (!@$_REQUEST['number']) { $errorsAndAlerts = "Add a number\n"; } $test = $_REQUEST['test']; echo $test; if (($_REQUEST['number']) == $test) { echo 'match'; }else{ echo 'no'; } } ?> <?php $number = rand(1,10); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Quick Enquiry Confirmation</title> </head> <body> <form method="post"> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <?php echo $number; ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td colspan="2"> <input name="quick_enquiry_name" type="text" id="quick_enquiry_name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" /> <input type="text" id="number" name="number" style="width:180px;" /> <input type="hidden" id="test" value="<?php echo $number;?>" style="width:180px;" /> </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit" /> </div></td> </tr> </table> <input type="hidden" name="submitForm" value="1" /> </form> Thanks
-
Hi all, thanks for the replies. Ok, in rough format (until i get it working). This is my code: <?php session_start(); ?> <?php // process form if (@$_REQUEST['submitForm']) { // error checking $errorsAndAlerts = ""; if (!@$_REQUEST['quick_enquiry_name']) { $errorsAndAlerts = "No name\n"; } if (!@$_REQUEST['number']) { $errorsAndAlerts = "Add a number\n"; } $_SESSION['number'] = rand(1, 10); if ($_REQUEST['number'] == $_SESSION['number']) { echo 'yay'; }else { echo 'no'; } } ?> <?php $number = rand(1,10); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Quick Enquiry Confirmation</title> </head> <body> <form method="post"> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <?php echo $number; ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td colspan="2"> <input name="quick_enquiry_name" type="text" id="quick_enquiry_name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" /> <input type="text" id="number" name="number" style="width:180px;" /> </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit" /> </div></td> </tr> </table> <input type="hidden" name="submitForm" value="1" /> </form> However, it works sometimes and not others! Grrr.... Something so simple can take sooooo much time!
-
Obvious really! Feeling rather foolish!!! Is someone able to help me out or point me in the right direction? many thanks
-
Hi, I a daft question. I use <?php $number = rand(1,10); ?> to generate a random number between 1 & 10 I then show that using <?php echo $number; ?> Why is it that if this is a simple form, when you submit it this doesn't work. It always returns no rather than match, whether you enter the same numer in the form or not! ARGHHHHHH! :'( if (($_REQUEST['number']) == $number) { echo 'match'; }else{ echo 'no'; } Guessing it's easy & im being daft! Thanks
-
validate form with php, if all ok then post data
jarvis replied to jarvis's topic in PHP Coding Help
Ideally I dont want to use javascript and php to validate and process, am fast running out of ideas on this one though. Is this the only options available? Thanks -
Hi All, Probably very simple but can't work it out. I've the following form <form method="post" action="sendEmail.php"> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td colspan="2"> Please enter the words below (anti-spam)<br /> <?php echo recaptcha_get_html($publickey, @$captchaError); ?> </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit"> </div></td> </tr> </table> <input type="hidden" name="submitForm" value="1" /> <input type="hidden" name="quick_enquiry_name" value="<?php echo htmlspecialchars($_POST['quick_enquiry_name']); ?>" /> <input type="hidden" name="quick_enquiry_email" value="<?php echo htmlspecialchars($_POST['quick_enquiry_email']); ?>" /> <input type="hidden" name="enquiry" value="<?php echo htmlspecialchars($_POST['enquiry']); ?>" /> </form> Some values a past in from a previous form. What I'm trying to do, is the above form has a recaptcha, sO I need to verify the input from here first, if it's ok, then process the form which sends an email using sendEmail.php. My validation is below: <?php // Get a key from http://recaptcha.net/api/getkey require_once('recaptchalib_comments.php'); if (preg_match("/domain.com/", $_SERVER['HTTP_HOST'])) { $publickey = ""; $privatekey = ""; } else if (preg_match("/domain.co.uk/", $_SERVER['HTTP_HOST'])) { $publickey = ""; $privatekey = ""; } if (@$_REQUEST['submitForm']) { $errorsAndAlerts = ""; if (!@$_REQUEST['recaptcha_response_field']) { $errorsAndAlerts .= "Please enter the two words displayed (this is to stop spam).<br/>"; } if (@$_REQUEST['recaptcha_response_field']) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errorsAndAlerts .= "Incorrect value for anti-spam validation, please try again.<br/>"; } $captchaError = $resp->error; } } ?> At the moment, blank fields in my recaptcha or the wrong words still process the form & therefore email as I can't work out how to test the form first. Any help is much appreciated!
-
form submit shows popup window with recaptcha and confirm button
jarvis replied to jarvis's topic in PHP Coding Help
Thanks, although I'm not sure how I would do it with my code: <?php // process form if (@$_REQUEST['submitForm']) { // error checking $errorsAndAlerts = ""; if (!@$_REQUEST['name']) { $errorsAndAlerts = "Please fill out all fields\n"; } if (!@$_REQUEST['email']) { $errorsAndAlerts = "Please fill out all fields\n"; } else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "That email address is not valid\n"; } if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please fill out all fields\n"; } $textToConvert = $_REQUEST['enquiry']; $convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert); // send email user if (!$errorsAndAlerts) { $to = "[email protected]"; $subject = "Quick Contact"; $email = $_REQUEST['email']; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; #$headers .= "Content-Type: text/html; charset=utf8\r\n"; $headers .= "From: $email \r\n"; $body = "<strong>Full name</strong>: ". $_REQUEST['name'] ."<br />"; $body .= "<strong>Email</strong>: ".$_REQUEST['email'] ."<br />"; $body .= "<strong>Enquiry</strong>: $convertedText<br /><br />"; $body .= "The user who sent this message had the IP address <strong>".$_SERVER['REMOTE_ADDR']."</strong><br />"; $message = $body; // Note: The above line must be flush left or you'll get an error // This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc // send message $mailResult = @mail($to, $subject, $message, $headers); if (!$mailResult) { die("Mail Error: $php_errormsg"); } // $errorsAndAlerts = "Thanks! We've sent your email."; $_REQUEST = array(); // clear form values } } ?> <!-- right quick_contact form --> <!-- quick_contact_title --> <div class="rh_quick_contact_title"> <img src="images/rh_quick_enquiry_title.jpg" width="232" height="31" /> </div> <!-- /quick_contact_title --> <!-- quick_contact_form --> <div class="rh_quick_contact_content"> <form method="post"> <input type="hidden" name="submitForm" value="1" /> <?php if (@$errorsAndAlerts): ?> <div style="color: red; font-weight: bold; font-size: 12px; font-family: arial;"> <?php echo $errorsAndAlerts; ?> </div> <?php endif ?> <table width="213" border="0" cellpadding="2" cellspacing="2"> <tr> <td align="center"> <input name="name" type="text" id="name" style="width:180px;" value="Name..." onclick="clickclear(this, 'Name...')" onblur="clickrecall(this,'Name...')" /> </td> </tr> <tr> <td align="center"> <input name="email" type="text" id="email" style="width:180px;" value="Email Address..." onclick="clickclear(this, 'Email Address...')" onblur="clickrecall(this,'Email Address...')"/> </td> </tr> <tr> <td align="center"> <textarea name="enquiry" id="enquiry" value="Enquiry..." onclick="clickclear(this, 'Enquiry...')" onblur="clickrecall(this,'Enquiry...')" style="width:180px;" rows="4"></textarea> </td> </tr> <tr> <td><div align="right"> <input type="image" src="images/blue_submit_button.jpg" value="Submit" alt="Submit"> </div></td> </tr> </table> </form> </div> <!-- /quick_contact_form --> Any pointers are most gratefully received! -
Hi All, Prob very simple but here goes. I've a form on a page, which needs a recaptcha field, due to design constraints however, it won't fit. I therefore need it so you fill in the form, click submit, a new window appears with the recaptcha field and a confirmation button. Once you click confirm, the form is processed and the email sent. What's the best way to do this please? The form script has the PHP to handle the emailing side.
-
Solved using $textToConvert = $_REQUEST['enquiry']; $convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert);
-
The page which has the enquiry form on has: <?php header('Content-type: text/html; charset=utf-8'); ?> If i alter this to iso, it fixes the email, however, it stuffs up the rest of the page. So, is there a way around this? Many thanks
-
Ok, I've altered my code and this should be correct, however, the encoding still isn't working. Here's my code: if (!$errorsAndAlerts) { $email = $_REQUEST['email']; $to = "[email protected]"; $subject = "Quick Contact"; $body = "Full name: ". $_REQUEST['name'] ."\n\n"; $body .= "Email: ".$_REQUEST['email'] ."\n\n"; $body .= "Enquiry: ". $_REQUEST['enquiry'] ."\n\n"; $body .= "The user who sent this message had the IP address ".$_SERVER['REMOTE_ADDR']."\n\n"; $message = $body; $headers = "MIME-Version: 1.0\r\n"; #html hdr $headers .= "Content-Type: text/html; charset=utf8\r\n"; $headers .= "From: $email \r\n"; #from // send message $mailResult = @mail($to, $subject, $message, $headers); if (!$mailResult) { die("Mail Error: $php_errormsg"); } I cannot see where I'm going wrong! Thanks
-
Hi, It's a plain text email, how easy is it to conver to html? Full name: {$_REQUEST['name']} Email: {$_REQUEST['email']} Enquiry: {$_REQUEST['enquiry']} The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}. __TEXT__; // Note: The above line must be flush left or you'll get an error // This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc // send message $mailResult = @mail($to, $subject, $message, "From: $from"); if (!$mailResult) { die("Mail Error: $php_errormsg"); } // $errorsAndAlerts = "Thanks! We've sent your email."; $_REQUEST = array(); // clear form values } } Many thanks
-
Hi All, I've got a simple enquiry form, it then uses the following code to send an email: // error checking $errorsAndAlerts = ""; if (!@$_REQUEST['name']) { $errorsAndAlerts = "Please fill out all fields\n"; } if (!@$_REQUEST['email']) { $errorsAndAlerts = "Please fill out all fields\n"; } else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "Please fill out all fields\n"; } if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please fill out all fields\n"; } // send email user if (!$errorsAndAlerts) { $from = $_REQUEST['email']; $to = "[email protected]"; $subject = "Quick Contact"; $message = <<<__TEXT__ Full name: {$_REQUEST['name']} Email: {$_REQUEST['email']} Enquiry: {$_REQUEST['enquiry']} Problem is it seems to add the following characters into the email: What can I do to stop that? TIA jarvis
-
Thanks I'll play around with that!
-
Thanks inversesoft123 , I'd come across that piece of code, however, couldn't see how to tie it in with my code.
-
Hi All, I've the following code: foreach ($subscribers as $record) { $from = "[email protected]"; $to = $record['email']; $subject = "Article Added to the ". $clientName . " client"; $message = "A new article entitled '". @$_REQUEST['title'] . "' has been added to the {$clientName} client"; $message .= "\n". @$_REQUEST['summary'] ."\n\n"; $message .= "\nClick here to to view it: http://www.domain.com/news.php?". @$_REQUEST['title'] ."-". $num; It works but if the title has spaces in, the link in the email fails. How can I replace the title with -? Thanks
-
Thanks all for your replies. Unfortunately, I'm not able to use the GROUPBY option. What if I therefore go through all the elements in the array and count them? Then remove if the number is greater than 1? Something like: <?php $record_count_arr = array_count_values($client_newsRecords); ?> <?php foreach($client_newsRecords as $record => $client) { if($record_count_arr[$client] > 1) { unset($client_newsRecords[$record]); } } ?> Although that gives an error: Warning: array_count_values(): Can only count STRING and INTEGER values! in ....php So may need some work!
-
Thanks thorpe. I would assume getrecords() retrieves the details from the db table, you then pass them into the code and reference each element. This code is from a CMS, not something I've done myself. However, I'm trying to modify a particular page hence this post. The GROUPBY didn't work as I tried that too. Apologies if this doesn't answer your questions or is a little vague!
-
Thanks pbs, that seems to shift the error, however, the list still contains duplicates!? Why are the simple things always the most annoying! Thanks
-
Thanks thorpe, where abouts? list($client_newsRecords, $client_newsMetaData) = getRecords(array_unique( 'tableName' => 'news', 'orderBy' => 'client ASC', )); All brackets close correctly?
-
Thanks again, I'd tried that: list($client_newsRecords, $client_newsMetaData) = getRecords(array_unique( But got the following error: Parse error: syntax error, unexpected T_DOUBLE_ARROW in Or have I not used it in the correct way? Thanks
-
Thanks for the reply, unfortunately, that doesn't work. I get the error: Unknown option 'groupBy' specified. Valid option names are: (tableName, where, orWhere, orderBy, limit, offset, perPage, loadUploads, allowSearch, requireSearchMatch, loadCreatedBy, useSeoUrls, loadListDetails, joinTable, debugSql, leftJoin, useCache, pageNum, ignoreHidden, ignorePublishDate, ignoreRemoveDate, requireSearchSuffix, includeDisabledAccounts, addSelectExpr) Hope that helps? Thanks again!