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

  • Home
  • SEARCH
  • 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 9220159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:16:59+00:00 2026-06-18T03:16:59+00:00

Is there any one know what should I do so that users are required

  • 0

Is there any one know what should I do so that users are required to fill in the input in request page only but not in create/update page? I had my own reason I want to do like that.

In User Model

array('user_email, user_name', 'required','on'=>'request'),  //I want this only occur when on my request page

In User Controller

public function actionRequest()
{
    $id=Yii::app()->user->uid;
    $model=$this->loadModel($id);

    if(isset($_POST['User']))
    {
        $model->attributes=$_POST['User'];
        if ($model->validate('request')) 
        {
            if($model->save())
            {
                $this->redirect(array('view','id'=>$uid));
            }
        }
    }

    $this->render('request',array(
        'model'=>$model,
    ));
}

But somehow this does not work.

  • 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-18T03:17:00+00:00Added an answer on June 18, 2026 at 3:17 am

    You will have to create your model with the scenario so that the rules applicable to that scenario can be applied.

    Let’s say your scenario is some_scenario, then when you declare the rules use like so:

    array('user_email, user_name', 'required', 'on'=>'some_scenario')
    // now the user_email, user_name will be required properties only when the scenario is 'some_scenario'
    

    Now to apply a scenario to a model we have to create that model instance with that scenario, like so:

    $model = new SomeModel('some_scenario');
    

    Here’s a yii wiki that you might want to read.

    Edit: In your case you can set the scenario after the model object is created, by directly setting the scenario property:

    $model = $this->loadModel($id);
    $model->scenario = 'request';
    
    // ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know there have any other way that (by not using json_encode and
Does any one know if there is kinda implementation/addon for VS 2008 SP1 for
Not a major question but definitely one that would be a nice one to
Does anyone know if there have been any changes in Azure publish to allow
Does anyone know if there are any (ideally free) alternatives to SilkTest for automated
There are many users, many groups that users can be part of. Each group
Are there any source control systems that require another user to validate the source
As we all know one big advantage of MVC is stateless. However if not
I know that this is not the first Thread about this permission, however the
Does anyone know if there is a way to generate different code in the

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.