peter_anderson Posted July 28, 2010 Share Posted July 28, 2010 I've decided to rewrite one a couple of my forms, to make them more user friendly. But I am having problems returning the error. I've created an array ($e) which has the field name ($e['field_name']) for the error, but it isn't displaying any errors. Here's the code: case "contact": $e = array(); if(isset($_POST['sb'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error,$evar){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name',$e['fullname']); } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.',$e['email_a']); } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.',$e['email_r']); } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.',$e['subject']); } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.',$e['problem']); } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.',$e['email_r']); } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; Can anyone see what the problem is? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/ Share on other sites More sharing options...
sKunKbad Posted July 28, 2010 Share Posted July 28, 2010 I would guess it is because your second parameter passed to show_error() doesn't exist at the time it is being passed. $e['whatever'] = show_error( 'sjdnflsndlg', $e['whatever'] ); See what I mean? If $e['whatever'] doesn't exist until you create it, then how can the value of $e['whatever'] include $e['whatever']? Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092209 Share on other sites More sharing options...
peter_anderson Posted July 28, 2010 Author Share Posted July 28, 2010 If I change the code so that the error shows if it is filled out, it shows the error: $e = array(); if(isset($_POST['submit'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email_a']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($fullname)){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.'); $continue = 0; } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.'); $continue = 0; } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.'); $continue = 0; } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.'); $continue = 0; } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.'); $continue = 0; } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092217 Share on other sites More sharing options...
radar Posted July 28, 2010 Share Posted July 28, 2010 <?php case "contact": $e = array(); if(isset($_POST['sb'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name'); } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.'); } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.'); } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.'); } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.'); } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.'); } } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; ?> try that, let me know what happens. Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092223 Share on other sites More sharing options...
radar Posted July 28, 2010 Share Posted July 28, 2010 i was wrong on this account -- edited to remove bad information -- Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092230 Share on other sites More sharing options...
peter_anderson Posted July 28, 2010 Author Share Posted July 28, 2010 @radar, no that doesn't fix it. Thanks anyway I'm struggling to see the problem. Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092239 Share on other sites More sharing options...
radar Posted July 29, 2010 Share Posted July 29, 2010 try this at the bottom of your page with this case in it.. echo "<pre>"; print_r($e); echo "</pre>"; this will print out the $e array in a way you can read it, and will tell us many things. Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1092600 Share on other sites More sharing options...
peter_anderson Posted July 30, 2010 Author Share Posted July 30, 2010 @radar, it prints: Array ( ) When no fields or some fields are filled in. $e = array(); if(isset($_POST['submit'])){ $fullname = $sql->real_escape_string($_POST['fullname']); $email_a = $sql->real_escape_string($_POST['email_a']); $email_r = $sql->real_escape_string($_POST['email_r']); $orderid = $sql->real_escape_string($_POST['orderid']); $subject = $sql->real_escape_string($_POST['subject']); $problem = $sql->real_escape_string($_POST['problem']); # Error Message function show_error($error){ $err = ' <span style="color: #ff0000"><strong>'.$error.'</strong></span>'; return $err; } # Check for isset if(!isset($_POST['fullname'])){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($fullname)){ $e['fullname'] = show_error('Please enter your full name'); $continue = 0; } if(!isset($_POST['email_a'])){ $e['email_a'] = show_error('Please enter your email address.'); $continue = 0; } if(!isset($_POST['email_r'])){ $e['email_r'] = show_error('Please re-enter your email address.'); $continue = 0; } if(!isset($_POST['subject'])){ $e['subject'] = show_error('Select a subject.'); $continue = 0; } if(!isset($_POST['problem'])){ $e['problem'] = show_error('Describe your problem.'); $continue = 0; } if(isset($_POST['email']) AND isset($_POST['email_r']) AND $email_a != $email_r){ $e['email_r'] = show_error('Your email addresses do not match.'); $continue = 0; } echo "<pre>"; print_r($e); echo "</pre>"; } $content = '<h2> Customer Support - Contact</h2> <p> For technical support, sales and product related questions: <a href="'.$tech_support.'" target="_blank">Technical Support</a>.</p> <p> For downloading, ordering, refund or other store related questions, please fill out the form below:</p> <form method="post" name="csupport"> <p> Please enter your full name:<br /> <input name="fullname" type="text" value="'.$fullname.'" />'.$e['fullname'].'</p> <p> Please enter your email address:<br /> <input name="email_a" type="text" value="'.$email_a.'" />'.$e['email_a'].'<br /> Please re-enter your email address:<br /> <input name="email_r" type="text" value="'.$email_r.'" />'.$e['email_r'].'</p> <p> Please enter your order number:<br /> <input name="orderid" type="text" value="'.$orderid.'" /></p> <p> Please select a subject for your enquiry:<br /> <select name="subject"><option selected="selected" value="">--Select--</option><option value="Billing Question">Billing Question</option><option value="Cancel / Refund Order">Cancel / Refund Order</option><option value="Download Question">Download Question</option><option value="Password Issues">Password Issues</option><option value="Order Question">Order Question</option><option value="Shipping Question">Shipping Question</option><option value="Other">Other</option></select>'.$e['subject'].'</p> <p> Describe your problem as best you can:<br /> <textarea cols="45" name="problem" rows="4">'.$problem.'</textarea>'.$e['problem'].'</p> <p> <input name="sb" type="hidden" value="sb" /><input name="submit" type="submit" value="Submit" /></p> </form> '; $title = 'Contact Support'; break; Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1093048 Share on other sites More sharing options...
radar Posted July 30, 2010 Share Posted July 30, 2010 k now try the same thing with $_POST and make sure that is printing out correctly. although it really shouldnt be inside the function.. it should be right before the ending ?> of the php file... that way it always displays Quote Link to comment https://forums.phpfreaks.com/topic/209124-form-error-checking-showing-the-error/#findComment-1093225 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.