我的视图中有一个名为Placeholder的下拉菜单 - "add_fields_placeholder"
,其值为是和没有。
当选择否时,我希望将占位符值排除在生成插入数据库的表单html行的$formData
数组之外。
当选择是时,我希望将占位符输入框add_fields_placeholderValue
中的文本提交到$formData
数组中。
我将如何实现这一目标?
public function add()
{
$this->form_validation->set_rules('add_fields_name', 'Name', 'trim|required|xss_clean');
$this->form_validation->set_rules('add_fields_value', 'Value', 'trim|xss_clean');
$this->form_validation->set_rules('add_fields_class', 'Class', 'trim|xss_clean');
$this->form_validation->set_rules('add_fields_placeholder', 'Placeholder', 'trim|required|xss_clean|callback_dropdown_check');
$this->form_validation->set_rules('add_fields_type', 'Type', 'trim|required|xss_clean|callback_dropdown_check');
if($this->form_validation->run() == FALSE)
{
$data['validation_errors'] = validation_errors('<div class="alert alert-error">', '</div>');
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Add Fields';
$this->load->view('_assets/dashHeader', $data);
$this->load->view('dashboard/add_fields', $data);
$this->load->view('_assets/footer');
}else{
$fieldName = $this->input->post('add_fields_name', TRUE);
$fieldValue = $this->input->post('add_fields_class', TRUE);
$fieldClass = $this->input->post('add_fields_defaultValue', TRUE);
//Removes Caps & spaces
$fieldNameStripped = strtolower(str_replace(" ", "", $fieldName));
$fieldValueStripped = strtolower(str_replace(" ", "", $fieldValue));
$fieldClassStripped = strtolower(str_replace(" ", "", $fieldClass));
//Default Form Details
$fieldLabel = '<label for="'. $fieldNameStripped . '">'. $fieldName. '</label>'."\n";
$formData = array(
'name' => ''.$fieldNameStripped.'',
'id' => ''.$fieldNameStripped.'',
'value' => ''.$fieldValueStripped.'',
'class' =>''.$fieldClassStripped.'',
'placeholder' => ''
);
if (isset($_REQUEST['add_fields_type']))
{
if($_REQUEST['add_fields_type'] == 'input')
{
$fieldField = form_input($formData, TRUE);
}
if($_REQUEST['add_fields_type'] == 'textarea')
{
$fieldField = form_textarea($formData, TRUE);
}
if($_REQUEST['add_fields_type'] == 'radiobutton')
{
$fieldField = form_radio($formData, TRUE);
}
if($_REQUEST['add_fields_type'] == 'checkbox')
{
$fieldField = form_checkbox($formData, TRUE);
}
$fieldTypeInsert = array(
'name' => ''.$fieldName.'',
'type' => ''.$_REQUEST['add_fields_type'].'',
'label' => ''.$fieldLabel.'',
'field' => ''.$fieldField.''
);
$this->form_model->insertField($fieldTypeInsert);
$data['validation_errors'] = '<div class="alert alert-success"><strong>Thank You</strong> Your Field Has Been Added</div>';
$data['contentMangement'] = $this->options_model->systemOptions();
$data['pageTitle'] = 'Add Fields';
$this->load->view('_assets/dashHeader', $data);
$this->load->view('dashboard/add_fields', $data);
$this->load->view('_assets/footer');
}
}
}
答案 0 :(得分:1)
你可以这样做:
$dropdown = $this->input->post('add_fields_placeholder', TRUE);
$dropdown_value = '';
if ($dropdown == 'yes') {
$dropdown_value = 'yes';
}
$formData = array(
'name' => ''.$fieldNameStripped.'',
'id' => ''.$fieldNameStripped.'',
'value' => ''.$fieldValueStripped.'',
'class' =>''.$fieldClassStripped.'',
'placeholder' => $dropdown_value
);