我有一个 codeigniter 应用程序。我的视图使用数据库行 ID 附加到输入名称以获取唯一 ID。这允许我在我的表单操作中使用所有输入,即更新。
我的视图语法:
<?php if(isset($records)) {?>
<table id="hor-minimalist-a">
<tr>
<th> </th><th> </th><th>Customer Name</th><th>postalcode</th>
<tr>
<?php if(isset($records)) : foreach ($records as $row) : ?>
<tr>
<td>
<?php echo anchor('masterdata/confirm_delete_customer/'.$row->id, img(array('src'=>'images/delete_icon.png','border'=>'0','alt'=>'Delete'))); ?>
</td>
<td>
<input type=checkbox name="editcustomer[]" id="editcustomer[]" value="<?php echo $row->id ?>">
</td>
<td>
<input class="inputwide" type="text" name="customer_name_<?php echo $row->id ?>" id="customer_name_<?php echo $row->id ?>" value="<?php echo $row->customer_name ; ?>" >
</td>
<td>
<input class="inputnarrow" type="text" name="postalcode_<?php echo $row->id ?>" id="postalcode_<?php echo $row->id ?>" value="<?php echo $row->postalcode ; ?>" >
</td>
</tr>
<?php endforeach ; ?>
</table>
<input type="submit" value="Update Checked Customers">
<?php endif; ?>
<?php echo form_close(); ?>
<?php } else {?>
<h4 id="warning"> No Customers currently in database</h4>
<?php } ?>
如您所见,输入name's
是id's
唯一的。
我的控制器语法如下:
function manage_customers()
{
$data['title']="Manage Customers";
//query model to get data results for form
$data=array();
if($query=$this->model_master_data->get_customer_records()){
$data['records']=$query;
}
$this->load->view("master_data/view_master_data_header",$data);
$this->load->view("master_data/view_master_data_nav");
$this->load->view("master_data/view_content_master_data_manage_customers",$data);
$this->load->view("master_data/view_master_data_footer");
$editcustomer = $this->input->post('editcustomer');
// single update - working
if( $this->input->post('editcustomer') != false )
{
foreach ($editcustomer as $row_id)
{
$data = array(
'postalcode' => $this->input->post('postalcode_'.$row_id),
'customer_name' => $this->input->post('customer_name_'.$row_id) );
$this->model_master_data->update_customer_records( $row_id, $data );
}
$this->session->set_flashdata('dbaction', 'Selected Records have been updated successfully');
redirect('masterdata/manage_customers', 'refresh');
}
}
如何使用 codeigniter 验证类来确保用户使用可信数据修改输入框?
怎么可能
$this->form_validation->set_rules("primary_contact_tell","
联系人告诉","required|xss_clean|min_length[10]|max_length[14]");
引用输入字段的正确动态名称?表单目前只有客户姓名和邮政编码,但需要添加其余字段。
预先感谢,一如既往。