【发布时间】:2012-01-25 20:30:10
【问题描述】:
我使用 Codeigniter 已经有一段时间了,虽然我并不总是发现表单验证像我确定的那样简单,但我从来没有遇到过任何大问题......直到现在!
我有一个由文本输入和文本区域组成的简单表单。表单从预填充开始,如果验证失败,则使用上次更改的状态重新填充它。
我的问题是 - textarea 需要接受英镑符号 (£)。它完全可以从数据库中填充文本,但是在提交时,无论表单是否验证,它都会将它们删除,无论我做什么!!
我已经在网上搜索过,只能找到将 htmlentities 之类的东西应用于验证规则的解决方案,但是如果我将 post 数据发送出去,甚至在规则之前,它已经被剥离了。
global_xss_filtering 在我的配置中设置为 false。
这让我发疯,浪费的时间比它应该的要多...有没有人解决这个问题,我知道我可能错过了一些非常简单的东西——这太让人抓狂了!
谢谢,
海伦
这是我的验证代码,虽然顶部的 firephp 日志显示它已经被删除,所以我看不出在这里做任何事情会有什么帮助......我已经尝试添加各种 php 函数,因为它建议@ 987654321@ 但根本没有区别。
public function edit_entry2($entry_id, $page_id) {
$this->firephp->log($_POST);
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|max_length[255]');
$this->form_validation->set_rules('address1', 'Address line 1', 'max_length[255]');
$this->form_validation->set_rules('address2', 'Address line 2', 'max_length[255]');
$this->form_validation->set_rules('address3', 'Address line 3', 'max_length[255]');
$this->form_validation->set_rules('address4', 'Address line 4', 'max_length[255]');
$this->form_validation->set_rules('county', 'County', 'required|max_length[255]');
$this->form_validation->set_rules('post_code', 'Post Code', 'max_length[10]');
$this->form_validation->set_rules('telephone1', 'Telephone 1', 'required|max_length[12]|is_natural');
$this->form_validation->set_rules('telephone2', 'Telephone 2', 'max_length[12]|is_natural');
$this->form_validation->set_rules('fax', 'Fax', 'max_length[12]|is_natural');
$this->form_validation->set_rules('email', 'Email address', 'valid_email');
$this->form_validation->set_rules('website', 'Website', 'max_length[255]');
$this->form_validation->set_rules('rating_awards', 'Rating/Awards', 'max_length[255]');
$this->form_validation->set_rules('description', 'Description', 'max_length[1000]');
$this->form_validation->set_rules('categories[]', 'Categories', 'callback_categories_check');
if ($this->form_validation->run() == FALSE)
{
$this->edit_entry($entry_id, $page_id);
}
else
{
$updated_entry = array('name'=>$_POST['name'], 'address1'=>$_POST['address1'], 'address2'=>$_POST['address2'], 'address3'=>$_POST['address3'], 'address4'=>$_POST['address4'], 'county'=>$_POST['county'], 'post_code'=>$_POST['post_code'], 'telephone1'=>$_POST['telephone1'], 'telephone2'=>$_POST['telephone2'], 'fax'=>$_POST['fax'], 'email'=>$_POST['email'], 'website'=>$_POST['website'], 'rating_awards'=>$_POST['rating_awards'], 'description'=>$_POST['description']);
$this->tourism_catalogue_model->update_entry($entry_id, $updated_entry, $_POST['categories']);
$this->index($page_id);
}
}
【问题讨论】:
-
你能发布你的验证码吗?
-
如果没有更好的解决方案,您可以随时将
£符号作为标签放在输入之前。 -
您是否使用 utf-8 作为编码?
-
@Colin - 好了,希望对您有所帮助:)
-
@JamWaffles - 它们将在文本区域内 - 用户将输入它们作为描述的一部分,所以恐怕这并没有真正的帮助。
标签: php codeigniter validation