[eluser]Gary Buckle[/eluser]
Hi webThink.
Many thanks for the prompt reply. I posted the entry quickly this morning without much thought.
First I pass the form to the view via an array:
<?php
$data['CustomerContact'] = array('name' => 'CustomerContact', 'id' => 'CustomerContact','maxlength' => '100',
pass the data to a view:
$this->load->view('addCustomer', $data);
?>
In the view I make an array from a ContactName field I have in a table called contacts.
Then I try to add the selected ContactName to a field called CustomerContact in a different table.
<?php
$contactArray = array();
$this->db->select('contact_id,ContactName');
$query = $this->db->get('contacts');
if ($query->num_rows() > 0)
{
foreach ($query->result()as $row)
{
$contactArray[$row->contact_id] = $row->ContactName;
}
}
echo form_dropdown('CustomerContact',$contactArray,'1');
echo form_submit('customerFormSubmit', 'Submit'); ?>
The function customerFormSubmit in the controller:
<?php
// get the data from the post array
$CustomerContact = $this->input->post('CustomerContact');
?>
I make a new postdata array to insert into the DB:
<?php
$postData = array('CustomerName' => $CustomerName,'PreviousName'=>$PreviousName,'Building'=> $Building,'Street' => $Street,'Town' => $Town,'County' => $County,'PostCode' => $PostCode,'CustomerContact'=>$CustomerContact,'Notes' => $Notes);
//debugging only
echo 'Post Data';
echo '<br>';
echo $CustomerName;
echo '<br>';
echo 'Customer Contact is ';
echo $CustomerContact;
echo '<br>';
?>
The $CustomerName uses a form_input in the view whereas $CustomerContact is the form_dropdown.
The result is as follows :
Post Data
Test Customer
Customer Contact is 1
So the form_input returns the correct result BUT form_dropdown returns the id ????
Any help is welcome.
Cheers
Gary