Yii Framework Forum: Change The Id That Model Creates For Form Inputs - Yii Framework Forum

Jump to content

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

Change The Id That Model Creates For Form Inputs Rate Topic: -----

#1 User is offline   mohsen.shakiba 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 06-October 13

Posted 29 March 2014 - 01:52 PM

hi,
I'm used to create my form manually.
there is disadvantage to this and that is when I'm validating my inputs the model sends back a message that doesn't comply with the way that I handle forms.
see this example of an error message that the model 'Users' sends to me
"{"Users_email":["Email is not a valid email address."]}"
the model is using the name "Users_email" cause normally this is the id of email input created by form widget
but in my custom made form I have a different id and stuff.
so I'm looking for a way that model would assign a different name for my input the way I need it to be.
tanx for this awesome community
0

#2 User is offline   Bogel 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 13-April 13

Posted 02 April 2014 - 03:33 AM

There are few solutions for you.

First, the best one, most recommended. Recode your application to use the proper way of Yii.

Second, if you only need to focus on getting the validation error message and keep the way of your view built, use the form widget and display the error message with

<div class="row">
    <?php echo $form->error($model, 'email'); ?>
</div>


Third, the focus is similar with the second one but you don't want to use the form widget, modifies your controller to add the lines for getting the validation error message of each model's attribute, keep it in the variable (one variable for one attribute), and pass the variable on view rendering. Your controller should add the line like this:

$model->validate();
$emailErrMessage = $model->getErrors('email');

0

#3 User is offline   mohsen.shakiba 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 06-October 13

Posted 05 April 2014 - 09:17 AM

View PostBogel, on 02 April 2014 - 03:33 AM, said:

There are few solutions for you.

First, the best one, most recommended. Recode your application to use the proper way of Yii.

Second, if you only need to focus on getting the validation error message and keep the way of your view built, use the form widget and display the error message with

<div class="row">
    <?php echo $form->error($model, 'email'); ?>
</div>


Third, the focus is similar with the second one but you don't want to use the form widget, modifies your controller to add the lines for getting the validation error message of each model's attribute, keep it in the variable (one variable for one attribute), and pass the variable on view rendering. Your controller should add the line like this:

$model->validate();
$emailErrMessage = $model->getErrors('email');



Ok, You know I'm Using it the proper way just I need the id to match my javascript, that's all.
anyway thanks.
I had to change my javascript file to get things to work.
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