2

yii-user 拡張機能をインストールし、登録のために tbl_profile テーブルにいくつかの列を追加しました。登録の種類は個人と法人の2種類

追加された列は次のとおりです。

会社の場合: company_name, comoany_type

個人用:電話

個人と会社の両方: mobile、fullname、country、states、post_code、address1、address2

登録タイプのラジオボタンの選択に応じて、jqueryを使用してフォームの入力フィールドを非表示および無効にしました。

両方の登録タイプの国選択についても同様です。2 つのオプション: 米国と他の国など

選択した登録タイプに従ってプロパティを検証するにはどうすればよいか混乱しています。たとえば、個人を選択した場合、会社のプロパティ フィールドの検証を無効にします。

プロパティを持つ 2 つのモデルがあります。

プロファイル: fullname、company_name、company_type、mobile、phone、firstaddress、secondaddress、country、states、postal_code

RegistrationForm : ユーザー名、パスワード、電子メール

対応するモデルのこれらのプロパティのルールも定義しました。

私はこのようなモデルを検証しようとしましたが、うまくいきません:

if(isset($_POST['RegistrationForm'])) {
    if($_POST['Profile']['account_type'] == 'personal')
    {
        //for personal account
        $profile->account_type = $_POST['Profile']['account_type'];
        $model->username = $_POST['RegistrationForm']['username'];
        $model->password = $_POST['RegistrationForm']['password'];
        $model->verifyPassword = $_POST['RegistrationForm']['verifyPassword'];
        $model->email = $_POST['RegistrationForm']['email'];
        $model->verifyCode = $_POST['RegistrationForm']['verifyCode'];
        $model->accept = $_POST['RegistrationForm']['accept'];
        $profile->fullname = $_POST['Profile']['fullname'];
        $profile->phone = $_POST['Profile']['phone'];
        $profile->ext = $_POST['Profile']['ext'];
        $profile->mobile = $_POST['Profile']['mobile'];
        if($_POST['choose_country'] == 'other')
        {
            $profile->country = $_POST['choose_country'];
            $profile->states = $_POST['profile_states'];
            $profile->postalcode = $_POST['Profile']['postalcode'];
            $profile->firstaddress = $_POST['Profile']['firstaddress'];
            $profile->secondaddress = $_POST['Profile']['secondaddress'];
        }
        if($_POST['choose_country'] == 'Nepal')
        {
            $profile->country = $_POST['choose_country'];
            $profile->firstaddress = $_POST['Profile']['firstaddress'];
            $profile->secondaddress = $_POST['Profile']['secondaddress'];
        }
    }
    if($_POST['Profile']['account_type'] == 'company')
    {
        //for organization account
        $profile->account_type = $_POST['Profile']['account_type'];
        $model->username = $_POST['RegistrationForm']['username'];
        $model->password = $_POST['RegistrationForm']['password'];
        $model->verifyPassword = $_POST['RegistrationForm']['verifyPassword'];
        $model->email = $_POST['RegistrationForm']['email'];
        $model->verifyCode = $_POST['RegistrationForm']['verifyCode'];
        $model->accept = $_POST['RegistrationForm']['accept'];
        $profile->fullname = $_POST['Profile']['fullname'];
        $profile->ext = $_POST['profile']['ext'];
        $profile->mobile = $_POST['Profile']['mobile'];
        $profile->company_name = $_POST['Profile']['company_name'];
        $profile->company_type = $_POST['Profile']['company_type'];
        $profile->designation = $_POST['Profile']['designation'];

        if($_POST['choose_country'] == 'Nepal')
        {
            $profile->country = $_POST['choose_country'];
            $profile->states = $_POST['Profile']['states'];
            $profile->postalcode = $_POST['Profile']['postalcode'];
            $profile->firstaddress = $_POST['profile']['firstaddress'];
            $profile->secondaddress = $_POST['profile']['secondaddress'];
        }
        if($_POST['choose_country'] == 'others')
        {
            $profile->country = $_POST['profile']['country'];
            $profile->firstaddress = $_POST['profile']['firstaddress'];
            $profile->secondaddress = $_POST['profile']['secondaddress'];
        }
    }

    //$model->attributes=$_POST['RegistrationForm'];
    //$profile->attributes=((isset($_POST['Profile'])?$_POST['Profile']:array()));

    if($model->validate()&&$profile->validate())
    {
    }
}

問題:

個人用ラジオ ボタンを選択してフォームを送信すると、 company_name 、会社の種類、および国の選択も同様に検証され、検証エラーが表示されます。ここで私が望むのは、個人または会社のタイプのラジオボタンの選択に応じて、モデルの検証を無効にすることです。

4

1 に答える 1