2012-01-08 88 views
0

我正在開發一個使用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); 
} 

,當我的print_r($ _ POST); 我得到了以下

Array ([title] => test title [desc] => test desc [url] => test url [cat] => javascript-tutorials [adcopy_challenge] => [email protected]@Szx1Cc29gNUENU8bgrSwY39APTC4lJjoCYJjyXvIJi2gPnq5tZIMpr0JgoGocL4bVHKrYt6Zyx3w-DAv2nYsjYiaeT-0C9Ec297zPussZKqXHDAdWTWT7ZcC1MklNV75-TPQzGDGu0yUgkDQWcRup.sNAOGBvK0cXCac1RzQ7T6adyI4bmcrNTpt7ANEEq2-1QcBgS8Uky6FxFHeFyGMDgzlJvqGyrBJfDRBNwroHBUXGHC1Jza9b54IS1.0E9kwlqZUOeBX9EomSEVcgrS6gA [ok] => 1 [by] => seekphp [submit] => Submit Tutorial) 1 
+1

自發猜測:問題中的表單域位於'

+0

@deceze我已經更新了問題並粘貼了print_r($ _ POST)調試信息 – 2012-01-08 06:42:26

回答

1

即使你認爲你知道應該是$_POST數組中的東西,不要以爲它,如果你想避免的通知。笨具有輸入類來簡化這一過程:

$_POST['doesnt exist']; // generates undefined index notice 
$this->input->post('doesnt exist'); // returns FALSE, no notice 

最重要的是,你有一個<noscript>標籤輸入,所以瀏覽器可以不發送值。

但是,當我在IE9提交表單工作正常,沒有發現錯誤。

你可能已經關閉了javascript,或者IE瀏覽器不正常(很有可能)。

0

我覺得$_POST["adcopy_response"]正在對驗證碼模型使用,但它不是在$_POST

0

最後我通過移除<table> <tr> <td>標籤

+0

是的,再看一遍,你的HTML對嵌套在'

'(可能更多)內的''無效。在這種情況下,不同瀏覽器的行爲會有所不同。 – deceze2012-01-08 08:03:09

0

將你的隱藏標記出<noscript>標籤的解決了這個問題。僅在您的瀏覽器禁用腳本時,<noscript>內的代碼纔可用。在瀏覽器中禁用腳本,然後運行它將非常有效。

相關問題