0

I have two tables:

  1. contacts
  2. phonetypes

In my add action, i populate a dropdown box from the phonetypes table (which has only 1 column, namely phone_type).

My contacts table has the fields: l_name, f_name, phone_type and number.

I have the dropdown's displayField as phone_type. Based on the selection in the dropdown I try to insert the phone_types field in the contacts table, but it inserts the id from the phonetypes table. But I want to insert the values and not the id...

Any help is appreciated.

My view code:

    echo $this->Form->create('Contact');
echo $this->Form->input('last_name', array('type'=>'text', 'size'=>10));
echo $this->Form->input('first_name');
echo $this->Form->select('phonetypes.phone_type',array('phone_type'=>'phone_type','options'=>$phone_type,'default'=>'phone_type'));
echo $this->Form->input('phone_number');
echo $this->Form->end('Save Entry');
3
  • It would help to see some of the code you are using. Try posting your Models and the add action you are referring to. Commented Feb 14, 2012 at 22:00
  • please add the code in your View where is the list of phonetypes, the problem may be there. Commented Feb 14, 2012 at 22:14
  • I have included my view code. Hope this helps in solving my simple problem Commented Feb 15, 2012 at 1:33

1 Answer 1

1

The better question is, if you are not using an ID for the primary key in the phone types table, why even use the database, why not just use a static array? If you want to use the database, you should ad the ID column and store the ID in the contacts table that references the phone type. Then to get the drop data you would do the following:

$this->set('phone_types', $this->PhoneType->find('list));

Then in the view, the form field will look like:

echo $this->Form->input('phone_type', array('options'=> $phone_types));

If you do NOT want to use the ID in the table, then just eliminate the table and set up a static array:

$this->set('phone_types', array('Home' => 'Home', 'Cell' => 'Cell', 'Work' => 'Work'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.