hi..
i have refer the following tutorial for dependent dropdown list
file:///C:/Documents%20and%20Settings/examsever/Desktop/3rdjune13/Using%20AJAX%20and%20CakePHP%20to%20dynamically%20populate%20select%20form%20fields%20_%20Jan.htm
when i select state next drop down list of contacts gives only one value
related to state
not giving all contacts related to state.plz help if possible
Tables
states contacts
id id
name name
state_id
In View
<?php echo $this->Form->create('Contact');
echo $this->Form->input('Contact.state_id', array('label' => 'state', 'empty' => '-- Pick a contact --','options'=>$states));
echo $this->Form->input('Contact.id', array('label' => 'contact', 'empty' => '-- Pick a state --','type'=>'select'));
echo $this->Form->end('Submit');
?>
<?php
$this->Js->get('#ContactStateId')->event(
'change',
$this->Js->request(
array('controller'=>'contacts','action'=>'ajax_contacts'),
array('update' => '#ContactId', 'dataExpression' => true, 'data' => '$("#ContactStateId").serialize()')
)
);
?>
In Controller
function ajax_contacts() {
$this->set('options',
$this->Contact->find('list',
array(
'conditions' => array(
'Contact.id' => $this->params['url']['data']['Contact']['state_id']
)
)
)
);
$this->render('/elements/ajax_dropdown', 'ajax');
}
ajax_dropdown.ctp
<?php foreach($options as $key => $val) { ?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php } ?>
-- i have refer the following tutorial for dependent dropdown list
file:///C:/Documents%20and%20Settings/examsever/Desktop/3rdjune13/Using%20AJAX%20and%20CakePHP%20to%20dynamically%20populate%20select%20form%20fields%20_%20Jan.htm
when i select state next drop down list of contacts gives only one value
related to state
not giving all contacts related to state.plz help if possible
Tables
states contacts
id id
name name
state_id
In View
<?php echo $this->Form->create('Contact');
echo $this->Form->input('Contact.state_id', array('label' => 'state', 'empty' => '-- Pick a contact --','options'=>$states));
echo $this->Form->input('Contact.id', array('label' => 'contact', 'empty' => '-- Pick a state --','type'=>'select'));
echo $this->Form->end('Submit');
?>
<?php
$this->Js->get('#ContactStateId')->event(
'change',
$this->Js->request(
array('controller'=>'contacts','action'=>'ajax_contacts'),
array('update' => '#ContactId', 'dataExpression' => true, 'data' => '$("#ContactStateId").serialize()')
)
);
?>
In Controller
function ajax_contacts() {
$this->set('options',
$this->Contact->find('list',
array(
'conditions' => array(
'Contact.id' => $this->params['url']['data']['Contact']['state_id']
)
)
)
);
$this->render('/elements/ajax_dropdown', 'ajax');
}
ajax_dropdown.ctp
<?php foreach($options as $key => $val) { ?>
<option value="<?php echo $key; ?>"><?php echo $val; ?></option>
<?php } ?>
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment