NickG21 Posted January 3, 2007 Share Posted January 3, 2007 hey everyone, i have a form i am validting and was wondering if i could store the span class of my errors in a seperate array that would be able to redisplay the locations the errors occurred in an .errortext instead of say a .basictext?[code]if (isset($_POST['submit'])) { $company = $_POST['CompanyName']; $name = $_POST['realname']; $email = $_POST['email']; $domainName = $_POST['ListOrDomainName']; $username = $_POST['Username']; $password = $_POST['Password']; $credit = $_POST['CreditCardNumber']; $error1 = ''; $error = array();if (empty($name)) { $error[] = "Your Name"; }elseif (!preg_match("/^([a-zA-Z])+/",$name)) { $error[] = "Your Name May Not Contain Numbers"; $name=""; }if(checkEmail($email) == FALSE) { $error[]="E-Mail Address"; $email = "";} if (empty($password)){ $error[]="";}elseif(strlen($password) < 6){ $error[]="Password";}if(!preg_match("/^([0-9])+/",$credit)){ $error[]="Credit Card Number"; }if(count($error) > 0) { echo "<big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br/>', $error). "</p>"; } else { require_once("formmail.php"); exit; }}?><style> .basictext { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color:#000066; } .errortext { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color:#C00000; font-weight: bold; }</style><tr> <td class="left"><a><span class="<?print $text?>">Company Name:</td> <td><input name="CompanyName" size="28" value="<?echo "$company"?>"></td> </tr> <tr> <td class="left"><font color="#FF0000">Your Name :</font></td> <td><input name="realname" size="28" value="<?echo "$name"?>"></td> </tr>[/code]there are a few of the sections in my code where i would want to implement this. any help is appreciatedthank you Quote Link to comment https://forums.phpfreaks.com/topic/32702-solved-errotext-in-form/ Share on other sites More sharing options...
ober Posted January 3, 2007 Share Posted January 3, 2007 I'm unclear on what the actual problem is. You're echoing the errors before you ever display the form or create the styles. If you want to use a different class on the errors, just echo the errors later on. Quote Link to comment https://forums.phpfreaks.com/topic/32702-solved-errotext-in-form/#findComment-152226 Share on other sites More sharing options...
NickG21 Posted January 3, 2007 Author Share Posted January 3, 2007 that isn't all of my code, what i am trying to do is if there is an error in one of the fields i want to change the text of the label from black to red say. The only thing is that if i have the class change on any error than everyone of the classes are going to be printed in the red text instead of just the areas that had the errors in them. here is my full code, if it helps.[code]<?phpfunction checkEmail($email) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) { return FALSE; } list($Username, $Domain) = split("@",$email); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(@fsockopen($Domain, 25, $errno, $errstr, 15)) { return TRUE; } else { return FALSE; } }}if (isset($_POST['submit'])) { $company = $_POST['CompanyName']; $name = $_POST['realname']; $email = $_POST['email']; $domainName = $_POST['ListOrDomainName']; $username = $_POST['Username']; $password = $_POST['Password']; $credit = $_POST['CreditCardNumber']; $text = ".basictext" $error = array();if (empty($name)) { $error[] = ""; }elseif (!preg_match("/^([a-zA-Z])+/",$name)) { $error[] = "Your Name May Not Contain Numbers"; $name=""; }if(checkEmail($email) == FALSE) { $error[]="E-Mail Address"; $email = "";} if (empty($password)){ $error[]="";}elseif(strlen($password) < 6){ $error[]="Password"; $text = ".errortext";}if(!preg_match("/^([0-9])+/",$credit)){ $error[]="Credit Card Number"; }if(count($error) > 0) { echo "<b>The Following Errors Were Found, Please Re-Enter:</b><br/>". implode('<br/>', $error). "</p>"; } else { require_once("formmail.php"); exit; }}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target=_blank><html xmlns="http://www.w3.org/1999/xhtml" target=_blank><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Cancellation</title><script language="javascript"><!--function DisableControlGroup(check, group){ var x, opt; if(check.checked) { opt = true; } else { opt = false; } for(x=0; x < group.length; x++) { group[x].disabled = opt; }}//--></script></head><style> .basictext { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color:#000066; } .errortext { font-family: Arial, Helvetica, sans-serif; font-size: 14px; color:#C00000; font-weight: bold; }</style><body> <form method="post" action="ContactUs.php" name="form1" onSubmit="return checkCheckBox(this)"><!-- form content --> <table class="qForm"> <tr> <td colspan="2" class="header">Contact Information:</td><td><font color="#FF0000"><span class="smalltype">*Required Field</font></span></td> </tr> <tr> <td class="left"><a><span class="<?print $text?>">Company Name:</td> <td><input name="CompanyName" size="28" value="<?echo "$company"?>"></td> </tr> <tr> <td class="left"><font color="#FF0000">Your Name :</font></td> <td><input name="realname" size="28" value="<?echo "$name"?>"></td> </tr> <tr> <td class="left"><font color="#FF0000">Your Email Address:</font></td> <td><input name="email" size="28" value="<?echo "$email"?>"></td> </tr> <tr> <td class="left">Your List Name or Domain Name:</td> <td><input name="ListorDomainName" size="28"></td> </tr> </table> <table class="qForm"> <tr> <td class="header">Customer Verification Information</td> </tr> <tr> <td ><p class="specialnote"><strong>To verify the authenticity ofyour request</strong>, please supply your username and password or thelast 6 digits of the credit card we have on file. If you do not havethis information please choose "resend the owners manual" and we willresend this information to the account owner.</p></td> </tr> <tr> <td style="padding: 0 0 0 20px; font-weight: bold; color:#96855E;">Option 1: Username and Password </td> </tr> </table> <table class="qForm"> <tr> <td class="left">Username:</td> <td><input name="Username" id="request"></td> </tr> <tr> <td class="left">Password:</td> <td><input type="password" name="Password" id="request"></td> </tr> </table> <table class="qForm"> <tr> <td style="padding: 0 0 0.5em 20px; font-weight: bold; color: #96855E;"> Option 2: Last 6 Digits of Credit Card Number <input name="CreditCardNumber" id="request" maxlength="6" size="6"> </td> </tr> <tr> <td style="padding: 0 0 1em 20px; font-weight: bold; color:#96855E;">You are not able to provide either of above. <div style="margin: 0.6em 2em 0 3em; padding: 0.3em;background-color: #F5FAFF; border: 1px solid #C2E3F5; color: #000;font-weight: normal;"> <input type="checkbox" name="Resemd" ID="OwnersManual" value="ResendOwnersManual" onClick="DisableControlGroup(this, request)"> Request to resend the owners manual. <p class="note" style="padding: 0.3em 1em; font-weight:normal;">Skip the rest of the fields and <a href="#submit">click the"Submit" button</a> at the bottom of the page.<br> For your protection, we cannot process your cancellation requestuntil we confirm your customer verification information. </p> </div> </td> </tr> <tr> <td class="header">Service to Cancel</td> </tr> <tr> <td class="oneColumnOptions"> <input name="ServiceName[]" id="request" type="radio" value="Announcement EmailList Hosting"> Announcement Email List Hosting<br> <input name="ServiceName[]" id="request" type="radio" value="Discussion EmailList Hosting"> Discussion Email List Hosting<br> <input name="ServiceName[]" id="request" type="radio" value="Web Hosting"> WebSite Hosting<br> <input name="ServiceName[]" id="request" type="radio" value="Pay Per Click BidManagement"> Pay Per Click Bid Management<br> <input name="ServiceName[]" id="request" type="radio" value="Dedicated Server">Dedicated Server Hosting<br> <input name="ServiceName[]" id="request" type="radio" value="Enterprise EmailFiltering"> Enterprise Email Filtering<br> <input name="ServiceName[]" id="request" type="radio" value="Email / WebmailAccounts"> Email / Webmail Accounts<br> <input name="ServiceName[]" id="request" type="radio" value="Other"> Other <input name="ServiceName" id="request" size="30"> </td> </tr> <tr> <td class="header">Reasons for Canceling <span class="note"style="padding-left: 1em; font-size: 80%;">(Check all that apply.)</span> </td> </tr> <tr> <td class="oneColumnOptions"> <input type="checkbox" name="Reasons[]" id="request" value="NotUsing Service"> Not Using Service<br> <input type="checkbox" name="Reasons[]" id="request"value="Dissatisfied with Features of Service" id="request"> Dissatisfied with Features of Service<br> <input type="checkbox" name="Reasons[]"value="Ineffective Business Solution" id="request"> Ineffective Business Solution<br><!-- specifically for mailing list --> <input type="checkbox" name="Reasons[]" id="request" value="Only Send Occational Mailings"> Only Send Occasional Mailings (<span class="note"style="font-weight: normal;">For Mailing List Hosting only</span>)<br> <input type="checkbox" name="Reasons[]" id="request" value="Poor Delivery of Email Newsletter to Subscribers">Poor Delivery of Email Newsletter to Subscribers (<span class="note"style="font-weight: normal;">For Mailing List Hosting only</span>)<br><!-- --> <input type="checkbox" name="Reasons[]" id="request" value="Found a Less Expensive Alternative"> Found a Less Expensive Alternative<br> <input type="checkbox" name="Reasons[]" id="request" value="Wentwith an In-house Solution"> Went with an In-house Solution<br> <input type="checkbox" name="Reasons[]" id="request"value="Technical Issues"> Technical Issues<br> <input type="checkbox" name="Reasons[]" id="request" value="TooDifficult to Use Service"> Too Difficult to Use Service<br> <input type="checkbox" name="Reasons[]" id="request" value="Dissatisfied with Technical Support"> Dissatisfied with TechnicalSupport<br> <input type="checkbox" name="Reasons[]" id="request" value="PoorCustomer Service"> Poor Customer Service<br> <input type="checkbox" name="Reasons[]" id="request" value="PoorBilling Process"> Poor Billing Process<br> <input type="checkbox" name="Reasons[]" id="request" value="WentOut of Business"> Went Out of Business<br> <input type="checkbox" name="Reasons[]" id="request" value="SoldCompany"> Sold Company<br> <input type="checkbox" name="Reasons[]" id="request" value="Other"> Other <input name="OtherReasons" id="request" size="30"> </td> </tr> <tr> <td class="header">Comments or Feedback </td> </tr> <tr> <td class="oneColumnOptions"><textarea name="Reasons[]" id="request" cols="40"rows="6"></textarea></td> </tr> <tr> <input type="hidden" name="Subject" value="Cancellation Form" /> <input type="hidden" name="required" value="realname, email, ListorDomainName" /> <input type="hidden" name="recipients" value="ngirard@netatlantic.com" /> <input type="hidden" name="mail_options" value="NoEmpty"/> <td style="padding: 1.5em 0; text-align: center;"> <input type="submit" name="submit" value="Submit" /> <input type="reset" value="Reset" /> </td> </tr> </table> </form></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32702-solved-errotext-in-form/#findComment-152251 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.