【发布时间】:2016-07-01 13:41:06
【问题描述】:
我正在使用 form 辅助类在 codeigniter 中创建一个表单。
但是使用 'form_dropdown("medium_type",$medium_type,"Select Medium")' 并没有使用 name 属性,因此表单验证在发布后不起作用。
谁能告诉我如何将名称传递给元素。
function controller(){
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->data['medium_type'] = $this->field_enums('notifications', 'medium_type');
$this->data['user_type'] = $this->field_enums('notifications', 'user_type');
$this->form_validation->set_rules('medium_type', 'Medium Type', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/notifications', $this->data);
}
else
{
$data = array(
'title' => $this->input->post('title'),
'medium_type' => $this->input->post('mediun_type'),
);
$this->notifications_m->insert($data);
}
$this->load->view('admin/notifications', $this->data);
}
表单代码 ` 标题
<div class="input-field col s12 m6 l6 margin-bottom-10px">
<?php echo form_dropdown("medium_type",$medium_type);?>
<label for="medium_tyoe">Medium Type</label>
<?php echo form_error('medium_type'); ?>
</div>
<div class="input-field col s12 m12 l12 margin-bottom-10px">
<?php echo $this->ckeditor->editor("content");?>
<?php echo form_error('content'); ?>
</div>
<div class="btn waves-effect waves-light col s8 m4 l4 offset-m4 offset-l4 offset-s2 ">
<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit')); ?>
<i class="material-icons right">send</i>
</div>
</div>
</div>
<?php echo form_close();?>`
【问题讨论】:
-
这里你的下拉列表有
name="medium_type" -
同时显示您的控制器代码
-
加上它是枚举值的下拉列表,我如何在该助手中传递空的数组字段(“”=>“选择介质类型”)?
标签: codeigniter post form-helpers