error in email validation

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpquery
Forum Newbie
Posts: 13
Joined: Thu Dec 04, 2008 3:29 am

error in email validation

Post by phpquery »

Hello,

Please have a look at the following codes & attached screen shots.

When we enter details in the fields mentioned in the screen shot named "email_html" & click on OK then it gives me an error as shown in the screen shot named "email_validation_error"

Code: Select all

validator.php

Code: Select all

</li><li style=\"\" class=\"li1\">require_once 'SystemComponent.php';</li><li style=\"\" class=\"li2\">class validator extends SystemComponent {</li><li style=\"\" class=\"li1\">var $errors; </li><li style=\"\" class=\"li2\">// A variable to store a list of error messages</li><li style=\"\" class=\"li1\">function validateNumber($theinput,$description = '')</li><li style=\"\" class=\"li2\">{</li><li style=\"\" class=\"li1\">if (is_numeric($theinput)) </li><li style=\"\" class=\"li2\">{</li><li style=\"\" class=\"li1\">return true; // The value is numeric, return true</li><li style=\"\" class=\"li2\">}</li><li style=\"\" class=\"li1\">else</li><li style=\"\" class=\"li2\">{</li><li style=\"\" class=\"li1\">$this->errors[] = $description; // Value not numeric! Add error description to list of errors</li><li style=\"\" class=\"li2\">return false; // Return false</li><li style=\"\" class=\"li1\">}</li><li style=\"\" class=\"li2\">}</li><li style=\"\" class=\"li1\">}</li><li style=\"\" class=\"li2\"></li><li style=\"\" class=\"li1\"></li><li style=\"\" class=\"li1\"></li><li style=\"\" class=\"li1\">
  email.php

Code: Select all

</li><li style=\"\" class=\"li1\">// Gather the data from the form, store it in variables</li><li style=\"\" class=\"li2\">$userEmail = $_POST['email'];</li><li style=\"\" class=\"li1\">$maxMessages = $_POST['maximum'];</li><li style=\"\" class=\"li2\">// Create a validator object</li><li style=\"\" class=\"li1\">require_once('validator.php');</li><li style=\"\" class=\"li2\">$theValidator = new Validator();</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">// Validate the forms</li><li style=\"\" class=\"li1\">//$theValidator->validateNumber($userEmail, 'Email Address');</li><li style=\"\" class=\"li2\">$theValidator->validateNumber($maxMessages, 'Maximum number of messages');</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">// Check whether the validator found any problems</li><li style=\"\" class=\"li1\">if ($theValidator->foundErrors())</li><li style=\"\" class=\"li2\">{</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">&nbsp; &nbsp; // The were errors, so report them to the user</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">&nbsp; &nbsp; echo 'There was a problem with: '.$theValidator->listErrors('<br>'); // Show the errors, with a line between each</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">}</li><li style=\"\" class=\"li1\">else</li><li style=\"\" class=\"li2\">{</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">&nbsp; &nbsp; echo "All ok, so now add the user to the mailing list";</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\">}</li><li style=\"\" class=\"li1\">&nbsp;</li><li style=\"\" class=\"li2\"></li><li style=\"\" class=\"li2\"></li><li style=\"\" class=\"li2\"></li><li style=\"\" class=\"li2\">


Please guide me on a resolution to this query.

Thanks in advance,

phpquery
Attachments
email_validation_error.JPG
email_validation_error.JPG (41.61 KiB) Viewed 445 times
email_html.JPG
email_html.JPG (40.8 KiB) Viewed 445 times
User avatar
Ziq
Forum Contributor
Posts: 194
Joined: Mon Aug 25, 2008 12:43 am
Location: Russia, Voronezh

Re: error in email validation

Post by Ziq »

Do you think it is a normal code? I cannot understand that you have written...

In any case this type of errors means that you didn't create the "foundErrors" method in your "validator" class. Check this class.
phpquery
Forum Newbie
Posts: 13
Joined: Thu Dec 04, 2008 3:29 am

Re: error in email validation

Post by phpquery »

Hi Ziq,

Thanks for a prompt response. I checked the class & everything looks ok to me. I am pasting the codes once again for your reference. I appreciate your time on trying to resolve my issue.

Code: Select all

 
require_once 'SystemComponent.php';
class validator extends SystemComponent {
var $errors; 
// A variable to store a list of error messages
function validateNumber($theinput,$description = '')
{
if (is_numeric($theinput)) 
{
return true; // The value is numeric, return true
}
else
{
$this->errors[] = $description; // Value not numeric! Add error description to list of errors
return false; // Return false
}
}
}
 
Thanks,

phpquery
phpquery
Forum Newbie
Posts: 13
Joined: Thu Dec 04, 2008 3:29 am

Re: error in email validation

Post by phpquery »

Hello Friends,

Just following up to see if any one got time to look at my issue & can guide me to a resolution.

Thanks,

phpquery
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: error in email validation

Post by John Cartwright »

Where do you see foundErrors() defined?

In the future, please do not bump your thread within 24 hours.
Post Reply