我的代码有问题,即在提交时选择的值user_support_documentaries
没有被提交到数组
我可以在页面提交之前查看 HTML 源代码,它显示填充的值标签 - 我不明白为什么所选项目没有被放入数组中。
HTML:
<label>
<input type="radio" id="user_dafapp_1" name="user_dafapp" value="1" class="checkbox" <?php echo selected_checkbox(set_value('user_dafapp',$grant['user_dafapp']) == 1) ?> /> <br />
</label>
<div id="user_support_documentaries_container" style="display: none;">
<?php echo form_dropdown('user_support_documentaries', $film_list, set_value('user_support_documentaries',$grant['user_support_documentaries']), 'id="user_support_documentaries"'); ?>
</div>
JS:
// checkout form enhancement
if ($("#user_dafapp_1").is(":checked")) // If checked
{
$("#user_support_documentaries_container").show("fast"); //show the hidden div
}
else
{
$("#user_support_documentaries_container").hide("fast"); //otherwise, hide it
}
$("input[name*='user_dafapp']").click(function ()
{
if ($("#user_dafapp_1").is(":checked"))
{
$("#user_support_documentaries_container").show("fast");
}
else
{
$("#user_support_documentaries_container").hide("fast");
}
});
控制器:
function op($action = NULL, $grant_id = NULL)
{
if ($this->session->userdata('user_role') != 'grantmaker')
{
redirect('grants');
}
$user_id = $this->session->userdata('user_id');
$results = $this->users_model->get_user_by_id($user_id);
$this->data['user'] = $results->row_array();
switch ($action) {
case "edit" :
$results = $this->grant_model->get($grant_id, $user_id);
if ($results->num_rows() == 0)
{
$this->session->set_flashdata('flash', 'Grant not found', 'error');
redirect('user/my_grants');
}
$grant = $results->row_array();
$this->data['submit_text'] = 'Save changes';
$page_title = 'Edit a grant';
break;
case "add" :
$grant = array(
'user_budget' => '',
'user_dafapp' => '',
'user_support_documentaries' => '',
'related_filmmakers' => '',
'user_related_filmmakers' => '',
'user_anoymous' => '',
);
$this->data['submit_text'] = 'Submit';
$page_title = 'Make a Grant application form';
break;
default :
$this->session->set_flashdata('flash', 'grant not found', 'error');
redirect('user/my_grants');
break;
}
$this->data['action'] = $action;
$this->form_validation->set_rules('user_budget','Budget','required|numeric|trim|xss_clean'); //Amount
$this->form_validation->set_rules('user_dafapp','Support','trim|xss_clean'); //Support
$this->form_validation->set_rules('user_support_documentaries','Support documentaries','trim|xss_clean'); //FILMS
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if ($this->form_validation->run() == FALSE)
{
$this->data['grant'] = $grant;
$this->data['grant_id'] = $grant_id;
$this->data['film_list'] = $this->film_model->get_select_options2();
build_page('user/my_grants/grant/op/add_edit_form', $this->data, $page_title, 'User');
}
else
{
$grant_data['user_budget'] = set_value('user_budget'); //Amount
$grant_data['user_dafapp'] = set_value('user_dafapp'); //Support
$grant_data['user_support_documentaries'] = ((set_value('user_dafapp') == 1) ? set_value('user_support_documentaries') : ''); //This Line
switch($action)
{
case('edit'):
$grant_data['grant_modified'] = date('Y-m-d H:i:s');
if ($this->grant_model->save($grant_data, 'edit', $grant_id) == TRUE)
{
$this->session->set_flashdata('flash', 'Grant updated', 'success');
}
break;
case('add'):
$grant_data['grant_created'] = date('Y-m-d H:i:s');
$grant_data['user_id'] = $user_id;
$grant_data['grant_active'] = 0;
if ($this->grant_model->save($grant_data, 'add', $grant_id) == FALSE)
{
log_message('error', "Failed to add grant {$grant_id} via the admin section");
$this->session->set_flashdata('flash', 'Failed to add grant - '.set_value('grant_name'), 'error');
}
else
{
$responder_array = array(
'%user_budget' => set_value('user_budget'),
'%user_dafapp' => ((set_value('user_dafapp') == 1) ? 'Support one or more documentaries on Name Approved List of films' : 'Support the general operations of Name'),
'%user_support_documentaries' => ((set_value('user_dafapp') == 1) ? set_value('user_support_documentaries') : '')
);
/*
$responder_array = array(
'%user_budget' => set_value('user_budget'),
'%user_dafapp' => ((set_value('user_dafapp') == 2) ? 'Support one or more documentaries on Name Approved List of films' : 'Support the general operations of Name'),
'%user_support_documentaries' => ((set_value('user_dafapp') == 2) ? set_value('user_support_documentaries') : ''),
'%user_related_filmmakers' => ((set_value('related_filmmakers')) ? set_value('user_related_filmmakers') : ''),
'%user_anoymous' => ((set_value('user_anoymous')) ? 'Yes' : 'No'),
);
*/
@$this->autoresponder->send('add_grant', $this->session->userdata('user_email'), $this->session->userdata('user_first_name') . " ". $this->session->userdata('user_surname'), $responder_array);
@$this->autoresponder->send('add_grant', NOTIFICATION_EMAIL, NULL, $responder_array);
$this->session->set_flashdata('flash', 'Your grant submission was successful', 'success');
}
break;
}
redirect("user/my_grants");
}
}