Welcome Guest, Not a member yet? Register   Sign In
Problems with Form_Dropdown
#3

[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>';

?&gt;

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


Messages In This Thread
Problems with Form_Dropdown - by El Forum - 03-27-2008, 01:44 AM
Problems with Form_Dropdown - by El Forum - 03-27-2008, 02:11 AM
Problems with Form_Dropdown - by El Forum - 03-27-2008, 03:09 PM
Problems with Form_Dropdown - by El Forum - 03-27-2008, 03:38 PM
Problems with Form_Dropdown - by El Forum - 03-27-2008, 05:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB