Before Save in a CActiveForm


I have a table where one field is determined by two other fields from another table and in the user interface I would like to reference those two other fields. I’m using a CActiveForm and I think I can just add public variables to the model for it to store the ID values of the two fields. I can’t however, retrieve them in my before save function. I tried using $_POST[‘id’] and I tried just accessing the private variable that I created;

Any Ideas?



I didn’t quite undestand what you want

are the 2 values you are trying to get constants?

if so use constants

or you need to perform a query to retrieve them?

if yes, use relations

Sorry about that. I should try to be more clear. The values are queried but they are drop down lists. I have populated the lists successfully, I’m just having trouble inserting what I need to insert. I’m working with an ActiveRecord of Table A. Table A has a foreign key value in it that the user shouldn’t see on the user interface. That foreign key value is unique based on two other fields in the table where it is a primary key. I want to put those two fields on my form but I have to insert the foreign key value not those two. I have no idea if that makes sense. I thought maybe I could grab the two values in the “beforeSave” event and then use a quick query and the $model->setAttributes() function to set the value correctly but I can’t grab the two values off of the form.

I hope that makes more sense.



Its easier to do the following

use Chtml::listData method to populate the value with the foreign key and the label as you are already using

something like the following










that is what I do