Jump to content

[SOLVED] errotext in form


NickG21

Recommended Posts

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 appreciated
thank you
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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]<?php
function 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 of
your request</strong>, please supply your username and password or the
last 6 digits of the credit card we have on file.  If you do not have
this information please choose "resend the owners manual" and we will
resend 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 request
until 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 Email
List Hosting"> Announcement Email List Hosting<br>
<input name="ServiceName[]" id="request" type="radio" value="Discussion Email
List Hosting"> Discussion Email List Hosting<br>
<input name="ServiceName[]" id="request" type="radio" value="Web Hosting"> Web
Site Hosting<br>
<input name="ServiceName[]" id="request" type="radio" value="Pay Per Click Bid
Management"> 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 Email
Filtering"> Enterprise Email Filtering<br>
<input name="ServiceName[]" id="request" type="radio" value="Email / Webmail
Accounts"> 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="Went
with 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="Too
Difficult to Use Service"> Too Difficult to Use Service<br>

<input type="checkbox" name="Reasons[]" id="request"
value="Dissatisfied with Technical Support"> Dissatisfied with Technical
Support<br>

<input type="checkbox" name="Reasons[]" id="request" value="Poor
Customer Service"> Poor Customer Service<br>
<input type="checkbox" name="Reasons[]" id="request" value="Poor
Billing Process"> Poor Billing Process<br>
<input type="checkbox" name="Reasons[]" id="request" value="Went
Out of Business"> Went Out of Business<br>
<input type="checkbox" name="Reasons[]" id="request" value="Sold
Company"> 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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.