CI の外部で正しく機能する一連の相互依存する選択リストがあります。Codeigniter で実装しようとしたとき、最初の選択リストが入力されていないため、エコーが適切にコード化されていないか、何がわからないかのいずれかで、うまくいきません。ここでのこの質問は、最初の選択リストのみを参照します。つまり、最初の選択リストは「関数の変更」なしでデータベースから直接入力されるため、jquery は表示されません。
モジュールは次のとおりです。
見る
<?php echo form_open('control_form/add_all'); ?>
<label for="f_state">State<span class="red">*</span></label>
<select id="f_state" name="f_state">
<option value=""></option>
<?php
foreach($result as $row)
{
echo '<option value="' . $row->pais_id . '">' . $row->pais_name . '</option>';
}
?>
</select>
<label for="f_city">City<span class="red">*</span></label>
<!--this will be filled based on the tree selection above-->
<select id="f_city" name="f_city" id="f_city_label">
<option value=""></option>
</select>
<label for="f_membername">Member Name<span class="red">*</span></label>
<input type="text" name="f_membername"/>
<?php echo form_close(); ?>
コントロール
public function add_all()
{
#Validate entry form information
$this->load->model('model_form','', TRUE);
$this->form_validation->set_rules('f_state', 'State', 'required');
$this->form_validation->set_rules('f_city', 'City', 'required');
$this->form_validation->set_rules('f_membername', 'Member Name', 'required');
$data['city'] = $this->model_form->get_state(); //gets the available groups for the dropdown
if ($this->form_validation->run() == FALSE)
{
$this->load->view('view_form_all', $data); # parece ser que vuelve a meter los mismos datos que tenia la Form
}
else
{
#Add Member to Database
$this->model_form->add_all();
$this->load->view('view_form_success');
}
}
モデル
<?php
class Model_form extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_state()
{
$query = $this->db->query('SELECT pais_id, pais_name FROM pais');
return $query->result();
}
function add_all()
{
$v_state = $this->input->post('f_state');
$v_membername = $this->input->post('f_membername');
$data = array(
'pais_id' => NULL,
'pais_name' => $v_state
);
$this->db->insert('members', $data);
}
}