【发布时间】:2015-03-02 10:05:57
【问题描述】:
我有以下代码。
<section class="section_class">
<input type="text" name="branch_contact_person_name[]" value="<?php echo set_value('branch_contact_person_name'); ?>" placeholder="Branch Contact Person Name" />
<input type="text" name="branch_contact_person_email[]" value="<?php echo set_value('shop_email'); ?>" placeholder="Branch Contact Person Email" />
<input type="text" name="branch_contact_person_mobile[]" value="<?php echo set_value('shop_mobile'); ?>" placeholder="Branch Contact Person Mobile" />
</section>
<input type="hidden" class="add_fields" />
我正在使用以下 jquery
$(document).ready(function() {
$("#add_next_branch").click(function() { //add_next_branch is a button
$('.section_class').clone().appendTo('.add_fields');
});
});
文本字段正在正确创建,但是当我提交所有文本字段为空白的表单时,它将显示正确的消息,但正在创建的文本字段正在消失。 这是控制器
function branch_details() {
$this->form_validation->set_rules('branch_contact_person_name[]', 'Site Name', 'required|xss_clean');
/*$this->form_validation->set_rules('product_category', 'Product Category', 'trim|required|xss_clean'); //This field is hidden
$this->form_validation->set_rules('product_brand','Product Brand','required|greater_than[0]');
//select location -- $this->form_validation->set_rules('shop_mobile', 'Shop Mobile', 'trim|required|min_length[6]|max_length[12]|xss_clean|numeric');
//$this->form_validation->set_rules('brand_pic', 'Product Image', 'trim|required|xss_clean');
$this->form_validation->set_rules('product_desc', 'Product Description', 'trim|required|xss_clean');
$this->form_validation->set_rules('product_price_type', 'Product Price Type', 'required|xss_clean');
$this->form_validation->set_rules('product_mrp', 'M.R.P ', 'required|xss_clean');
*/
$data = array();
$this->load->view('templates/homepage_header');
if ($this->form_validation->run() == FALSE)
{
$data['action_name'] = 'branch_details';
}
else
{
$data['action_name'] = 'shop_view';
}
$this->load->view('shop_view',$data);
}
【问题讨论】:
-
你说的离开是什么意思..
-
我不明白你的问题,但你有一个错字,你忘了结束
"->class="section_class" -
Going off - 我的意思是附加到 add_field 的元素正在从 DOM 中删除
-
谢谢@AdrienXL 我改变了。
-
您的表单在提交时会被刷新,因此克隆的字段不会持续存在。你能提供你的控制器代码吗?
标签: javascript php jquery validation codeigniter