开发者

Unable to throw my hidden input to Controller

I’m having a bit problem here. It seem I can’t throw my hidden input to my controller. It return blank T_T.

this is my view

<?php 
    foreach($users->result() as $item){
        echo "<tr><td>&nbsp;&nbsp;".$item->username."</td>
                  <td><a href=''>".$item->fullname."</a></td>
                  <td>".$item->data_display."</td>
                  <td align='center'>
                  <a href='".base_url()."user_accounts/approve/".$item->user_id."' class='";
                  if($item->display==1) {
                        echo "approve"; 
                  }else 
                        echo "pending";
        echo "'><input type='hidden' name='role' value='".$item->data_id."'/></a></td>
                  <td><a href='' class='edit'></a></td>
                  <td align='center'><a href='' class='del'></a></td></tr>";
    }
    ?>  

my controller

$item = $this->uri->segment(3);
    $role = $this->input->post('role');
$query = $this->main->getAll开发者_如何学GoUser_clause($item,$role)->row(); 

and this is the output of my query

SELECT user_id, a.data_id, fullname, username, pps_c.data_display, a.display,fname,mname,lname FROM (SELECT ad_userid user_id, ad_dataid data_id,concat_ws(' ',fname,mname,lname) as fullname, ad_username username, display,fname,mname,lname FROM pps_admin_users UNION SELECT user_id, data_id,concat_ws(' ',fname,mname,lname) as fullname, username, display,fname,mname,lname FROM pps_users) a LEFT JOIN pps_dataset pps_c ON a.data_id=pps_c.data_id WHERE user_id = 12 AND data_id = ORDER BY a.data_id ASC

As you can see my data_id = ‘’ //blank.

Can anyone help me with this..


You are not passing a form to the controller, so <input type="hidden" ...> does not get sent to the server and $this->input->post('whatever') will always be empty. In other words, <input > does not work with <a href="">whatever</a>.

You need to either add the role to the href in the link, or you need to create an actual form which includes fields for your data and buttons to submit that data to the server.

Also, if you are using double quotes when echo'ing, you can wrap variables in {$my_variable} and avoid the ".$my_variable." stuff as shown below (does NOT work with single quote echo'ing).

<?php 
foreach($users->result() as $item){
   if($item->display==1) {
                    $class = "approve"; 
              }else{
                    $class = "pending";
              }
    $base_url = base_url();
    echo "<tr><td>&nbsp;&nbsp;{$item->username}</td>
              <td><a href=''>{$item->fullname}</a></td>
              <td>{$item->data_display}</td>
              <td align='center'>
              <a href='{base_url}user_accounts/approve/{$item->user_id}/{$item->data_id}/' class='{$class}'></a></td>
              <td><a href='{base_url}item/edit/{$item->user_id}/' class='edit'></a></td>
              <td align='center'><a href='{base_url}item/edit/{$item->user_id}/' class='del'></a></td></tr>";
}
?>  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜