Jump to content


Photo

Validation... AAAAAAAAAAA!


  • Please log in to reply
4 replies to this topic

#1 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 04 September 2006 - 09:39 AM

Hey,

Iv got several functions for checking if name is letters only, telephone is numbers etc.. all that works, but how can I put all these functions included into one function for a form?

Iv got:

function checksignup(){
	var valid = 0;
	
	
	return checksurname();
	return checkfirstname();
	return checktelephone();
	
	if (valid==0) {
		return true;
	}
}

I was hoping the above checked the other functions and if valid=0 then its able to submit the form, but if any are returning 1 (that would be an error) then do not submit the form...

Help? Please?

TIA.

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 04 September 2006 - 02:17 PM

If all your check functions return 0 if check was valid and say 1 if there was a problem then...
function checksignup(){
	var valid = 0;
	
	
	valid = checksurname();
	if (valid == 0)
		valid = checkfirstname();
	if (valid == 0)
		valid = checktelephone();
	
	if (valid==0) {
		return true;
	}
}

follow me on twitter @PHPsycho

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 September 2006 - 02:35 PM

or, simply do this:
function checksignup() {
  if (!checksurname()) return false;
  if (!checkfirstname()) return false;
  if (!checktelephone()) return false;
  return true;
}

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 04 September 2006 - 02:42 PM

Thats why I shoudl do more js!!!! ;)
follow me on twitter @PHPsycho

#5 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 05 September 2006 - 08:09 AM

Thank you very much for the repies.

Both solutions work great - gone with obsidian's as it was shorter code and got more validation to add.

Many thanks!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users