我正在使用CodeIgniter开发一个应用程序。在我的应用程序中,当我在firefox 10.0中提交表单时,我收到此错误
Message: Undefined index: adcopy_response
但是当我在IE 9中提交表单时,我的应用程序运行正常。 IE中没有发现错误。可以任何一个。我的HTML代码是
<table>
<form action="" method="post">
<tr id="row">
<td><b>Title:</b></td>
<td>
<input type="text" style="width:450px;" name="title" value="" />
</td>
</tr>
<tr id="row">
<td><b>Description:</b></td>
<td>
<textarea style="width:450px;" name="desc" cols="35" rows="10"></textarea>
</td>
</tr>
<tr id="row">
<td><b>URL:</b></td>
<td>
<input type="text" style="width:450px;" name="url" value="" />
</td>
</tr>
<tr id="row">
<td><b>Category:</b></td>
<td>
<select name="cat">
<option value="">Select Category</option>
<option value="ajax-tutorials">AJAX Tutorials</option><option value="asp-tutorials">ASP Tutorials</option><option value="asp.net-tutorials">ASP.NET Tutorials</option><option value="codeigniter-tutorials">CodeIgniter Tutorials</option><option value="css-tutorials">CSS Tutorials</option><option value="html-tutorials">HTML Tutorials</option><option value="javascript-tutorials">JavaScript Tutorials</option><option value="jquery-tutorials">jQuery Tutorials</option><option value="ms-sql-tutorials">Ms SQL Tutorials</option><option value="mysql-tutorials">MySQL Tutorials</option><option value="php-tutorials">PHP Tutorials</option><option value="programming-tutorials">Programming Tutorials</option><option value="wordpress-themes">Wordpress Themes</option><option value="wordpress-tutorials">WordPress Tutorials</option><option value="xml-tutorials">XML Tutorials</option> </select>
</td>
</tr>
<tr id="row">
<td><b>Prove you're not a robot</b></td>
<td>
<script type="text/javascript" src="http://api.solvemedia.com/papi/challenge.script?k=hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf"></script>
<noscript>
<iframe src="http://api.solvemedia.com/papi/challenge.noscript?k=XXXX" height="300" width="500" frameborder="0"></iframe><br/>
<textarea name="adcopy_challenge" rows="3" cols="40"></textarea>
<input type="hidden" name="adcopy_response" value="manual_challenge"/>
</noscript> </td>
</tr>
<tr id="row">
<td>
<input type="hidden" name="ok" value="1" />
<input type="hidden" name="by" value="seekphp" />
<input type="submit" name="submit" value="Submit Tutorial" />
</td>
</tr>
</form>
</table>
和CI代码是
function submit(){
$privkey="XXXX";
$hashkey="XXXX";
$data['err'] = "";
$this->form_validation->set_rules('title', 'Title', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('desc', 'Description', 'required|trim|xss_clean|htmlentities');
$this->form_validation->set_rules('url', 'URL', 'required|trim|xss_clean');
$this->form_validation->set_rules('cat', 'Category', 'required|trim|xss_clean');
if($this->form_validation->run() == FALSE){
} else {
$title = $this->input->post('title');
$desc = $this->input->post('desc');
$url = $this->input->post('url');
$cat = $this->input->post('cat');
$by = $this->input->post('by');
$ok = $this->input->post('ok');
$solvemedia_response = $this->Captcha_model->solvemedia_check_answer($privkey,
$_SERVER["REMOTE_ADDR"],
$_POST["adcopy_challenge"],
$_POST["adcopy_response"],
$hashkey);
if ($solvemedia_response->is_valid) {
if($this->Tutorial_model->add_tut($title, $desc, $url, $cat, $by, $ok) == TRUE){
$this->session->set_flashdata('msg', "Tutorial has been added successfully.");
redirect(base_url().'user/submit', 'refresh');
} else {
$this->session->set_flashdata('err', "Tutorial may already exist or there is an error while submitting tutorial.");
redirect(base_url().'user/submit', 'refresh');
}
} else {
$data['err'] = "Incorrect Captcha.";
}
}
$data['cats'] = $this->Category_model->get_all_cats();
$this->load->view("user/submit_view", $data);
}
当我打印__($ _ POST); 我得到以下
Array ( [title] => test title [desc] => test desc [url] => test url [cat] => javascript-tutorials [adcopy_challenge] => 2@hse4RWPEOMayq3QzRQiUZTnTtVkI8Jmf@Szx1Cc29gNUENU8bgrSwY39APTC4lJjoCYJjyXvIJi2gPnq5tZIMpr0JgoGocL4bVHKrYt6Zyx3w-DAv2nYsjYiaeT-0C9Ec297zPussZKqXHDAdWTWT7ZcC1MklNV75-TPQzGDGu0yUgkDQWcRup.sNAOGBvK0cXCac1RzQ7T6adyI4bmcrNTpt7ANEEq2-1QcBgS8Uky6FxFHeFyGMDgzlJvqGyrBJfDRBNwroHBUXGHC1Jza9b54IS1.0E9kwlqZUOeBX9EomSEVcgrS6gA [ok] => 1 [by] => seekphp [submit] => Submit Tutorial ) 1
答案 0 :(得分:1)
即使您想,您也知道$_POST
数组中的内容,如果您想避免通知,请不要假设它。 Codeigniter具有Input类以使其更容易:
$_POST['doesnt exist']; // generates undefined index notice
$this->input->post('doesnt exist'); // returns FALSE, no notice
最重要的是,您在<noscript>
标记中输入了内容,因此浏览器可能无法发送该值。
但是当我在IE9中提交表单时,它运行正常,没有发现错误。
你有可能关闭了javascript,或IE是行为不端(很有可能)。
答案 1 :(得分:0)
我认为$_POST["adcopy_response"]
正用于Captcha模型,但不在$_POST
答案 2 :(得分:0)
最后,我通过删除<table> <tr> <td>
代码
答案 3 :(得分:0)
将隐藏的标记放在<noscript>
标记之外。仅当您的浏览器禁用了脚本时,<noscript>
中的代码才有效。在您的浏览器中禁用脚本,然后运行它将完美地工作。