Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:50:05+00:00 2026-06-12T23:50:05+00:00

problem defenition i have one model called ‘user.php’ i have some validation rules on

  • 0

problem defenition

i have one model called ‘user.php’
i have some validation rules on the same as follows
i am now going to create a password reset form
in that form i have a text box name email (same email used in user model)
in password reset form i would like to check wheather this user is a registered one if it a registered one will send the password reset link

I DONT KNOW HOW TO VAIDATE THIS EMAIL FIELD , ANY HELP HIGHLY APPRECIABLE AS I AM NEW IN YII

user.php

    class Users extends CActiveRecord
{
public $cpassword;
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
public function tableName()
    {
        return 'users';
    }
public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('email, password, user_type , cpassword','required'),
            array('email', 'length', 'max'=>200),
                        array('email', 'unique'),
                        array('email', 'email'),
            array('password', 'length', 'max'=>300),
                        array('cpassword', 'length', 'max'=>300),
            array('user_type', 'length', 'max'=>5),
                        array('cpassword', 'compare', 'compareAttribute' => 'password'),

            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, email, password, user_type ', 'safe', 'on'=>'search'),
        );
    }
public function relations()
    {

return array(
        );
    }
public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'email' => 'Email',
            'password' => 'Password',
            'user_type' => 'User Type',
                        'cpassword' => 'Confirm Password'
        );
    }
public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id);
        $criteria->compare('email',$this->email,true);
        $criteria->compare('password',$this->password,true);
        $criteria->compare('user_type',$this->user_type,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }
        public function beforesave()
        {
            $this->password=md5($this->password);
            return true;
        }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:50:06+00:00Added an answer on June 12, 2026 at 11:50 pm

    You can check on the submit with something like:

    $user = User::model()->find("email = '".trim($model->email)."'");
    if (!empty($user)){
         // users exists
    } else {
        // user does not exist
    }
    

    If you really want to use the model, you can setup a rule where email must be unique like so:

    array('email', 'unique', 'message' => 'Email already in use'),
    

    You can then check if the model validates on the submit, specifically the email field. If it doesnt validate the email address exists

    Last, you can validate a single model attribute like so:

    if($model->validate(array('attribute_name')) 
         // valid
    }
    

    Here is one way of doing the complete action (not the best way but the easiest to understand!)

    public function actionResetpassword(){
            $model = new User;
            if(isset($_POST['User'])){
                $model->attributes = $_POST['User']; // this is the form as completed by the user
                $user = User::model()->find("email = '".trim($model->email)."'");
                if (!empty($user)){
                    // send user their new email
                    $this->render("passwordreset"); // user exists, render confirmtion page
                } else {
                    // user does not exist, render form and pass $error_message variable with messasge 
                    $this->render("resetpassword",array(
                        "model"         =>  $model,
                        "error_message" =>  "No such user found!",
                    ));
                }
        } else {
            // this will be rendered if the user has not submitted the form yet
            $this->render("resetpassword",array(
                "model" =>  $model,
            ));
        }       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model User and when I create one, I want to pragmatically
I have problem with mongomapper associations. I have one class names User and other
I have a problem understanding one style definition in Windows 8 metro apps. When
Problem: I have two array where one produce a category and the second produce
I have 3 model, User, Post, Comment with definition like below class Post <
Well, the problem is as follows. I have models hierarchy as follows: class A
I have two PHP scripts. One acts as a backend, and contains a class
Problem: I have a table that prints out vertical but I would like it
Problem: I'm streaming my video from a php file with stream_get_contents(); using Flowplayer as
Lets say I have three django model classes - lets call them A, B

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.