我有一些代码,无论电子邮件提交NULL值。我已经使用了每个验证规则,它仍然在提交时为电子邮件提交NULL值。
<?php php echo form_label('First Name :'); ?> <?php echo form_error('dfirstName'); ?><br>
<?php echo form_input(array('id' => 'dfirstName', 'First Name' => 'dfirstName')); ?><br>
<?php echo form_label('Last Name :'); ?> <?php echo form_error('dlastName'); ?><br />
<?php echo form_input(array('id' => 'dlastName', 'Last Name' => 'dlastName')); ?><br />
<?php echo form_label('E-mail :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'e-mail' => 'demail')); ?><br />
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
//Validating firstName Field
$this->form_validation->set_rules('dfirstName', 'FirstName', 'required|min_length[4]|max_length[15]i');
//Validating lastName Field
$this->form_validation->set_rules('dlastName', 'LastName', 'required|min_length[4]|max_length[15]');
//Validating Email Field
$this->form_validation->set_rules('demail', 'e-mail', 'trim|alpha_numeric|max_length[30]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('schedule_submit');
} else {
//Setting values for tabel columns
$data = array(
'e-mail' => $this->input->post('demail'),
'LastName' => $this->input->post('dlastName'),
'FirstName' => $this->input->post('dfirstName')
);
//Transfering data to Model
$this->acom_insert->form_insert($data);
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('acom_success', $data);
}
答案 0 :(得分:0)
我知道这里有什么问题,唯一遗漏的是NAME。
发布值时,PHP依赖于输入类型的名称。所以只需在每个输入元素上添加名称。
这是您的代码
<?php echo form_input(array('id' => 'demail', 'e-mail' => 'demail')); ?><br />
以下是缺少的内容
<?php echo form_input(array('name' => 'demail','id' => 'demail', 'e-mail' => 'demail')); ?><br />
PHP帖子的名称不是id:)
修改强>
我已经编辑了我的答案。请尝试一下,如果这不起作用,你能用表格标签显示整个表格吗?
答案 1 :(得分:0)
这里您的视图的表单输入参数是错误的,对于您没有使用名称参数的所有3个字段。您可以按照此代码 -
<?php php echo form_label('First Name :'); ?> <?php echo form_error('dfirstName'); ?><br>
<?php echo form_input(array('id' => 'dfirstName', 'name' => 'dfirstName')); ?><br>
<?php echo form_label('Last Name :'); ?> <?php echo form_error('dlastName'); ?><br />
<?php echo form_input(array('id' => 'dlastName', 'name' => 'dlastName')); ?><br />
<?php echo form_label('E-mail :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'name' => 'demail')); ?><br />