Yii Framework Forum: validate email without a model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

validate email without a model Rate Topic: -----

#1 User is offline   vassy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 14-October 09

Posted 05 March 2010 - 08:43 AM

Hello.

What would be the best way to run Yii email validator outside of the model?
Ex.: user submits a list of emails (separated by commas), I explode them into array and need to run email validation for each item.

Should I create a dummy model or is there any better solution?

Thank you.
0

#2 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 05 March 2010 - 10:56 AM

View Postvassy, on 05 March 2010 - 08:43 AM, said:

Hello.

What would be the best way to run Yii email validator outside of the model?
Ex.: user submits a list of emails (separated by commas), I explode them into array and need to run email validation for each item.

Should I create a dummy model or is there any better solution?

Thank you.


(not tested).
$validator = new CEmailValidator;
if($validator->validateValue("test@domain.tld"))
{
    // valid
}else{
    // invalid
}

php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#3 User is offline   vassy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 14-October 09

Posted 05 March 2010 - 11:01 AM

CEmailValidator does not have a method named "validateValue".
0

#4 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 05 March 2010 - 11:08 AM

View Postvassy, on 05 March 2010 - 11:01 AM, said:

CEmailValidator does not have a method named "validateValue".


I just tested for myself and it works

		$validator = new CEmailValidator;
		if($validator->validateValue("test@gmail.com"))
			echo "validated";

php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#5 User is offline   qwerty 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 290
  • Joined: 20-November 08

Posted 05 March 2010 - 11:19 AM

Try validateAttribute() method.
0

#6 User is offline   jayrulez 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 348
  • Joined: 29-July 09

Posted 05 March 2010 - 11:28 AM

View Postqwerty, on 05 March 2010 - 11:19 AM, said:

Try validateAttribute() method.


Validate attribute works with models and does not return a boolean value.

read the source http://code.google.c...ilValidator.php

CEmailValidator::validateValue($value) is the method to use.
php:
foreach(array('cat', 'dog', 'cow') as $animal) echo $animal."\n";

python:
[(animal, print(animal)) for animal in ['cat', 'dog', 'cow']]

ruby:
['cat', 'dog', 'cow'].each {|animal| puts animal}


You say Tomato, I say Tomato.
0

#7 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 614
  • Joined: 08-May 09

Posted 05 March 2010 - 11:41 AM

validateValue() is available in SVN but not in a official relase so far, isnt it?
0

#8 User is offline   Driss 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 27-January 11

Posted 07 February 2011 - 05:37 AM

I usually use validateValue() wich does what needs to be done
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users