Welcome Guest, Not a member yet? Register   Sign In
Unable to throw my hidden input to Controller
#1

[eluser]Wondering Coder[/eluser]
hi guys,

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
Code:
<?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 >user_id."' class='";
                      if($item->display==1) {
                            echo "approve";
                      }else
                            echo "pending";
            echo "'>&lt;input type='hidden' name='role' value='".$item-&gt;data_id."'/></a></td>
                      <td><a href='' class='edit'></a></td>
                      <td align='center'><a href='' class='del'></a></td></tr>";
        }
        ?&gt;
my controller
Code:
$item = $this->uri->segment(3);
        $role = $this->input->post('role');
$query = $this->main->getAllUser_clause($item,$role)->row();

and this is the output of my query
Code:
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..
#2

[eluser]jblack199[/eluser]
to me it looks like some html formatting issues...

in the code, it seems to all start at this line: <a >user_id."' class='"; which is an apparent syntax error. as in you're in the end missing a " because of the improper HTML.

also your else statement is missing a { giving you an improper else clause... and the HTML at:


echo "'>&lt;input type='hidden' name='role' value='".$item-&gt;data_id."'/></a></td>

is also wrong, this one i dont know what you're trying to do with that first echo, and the closing link tank after the hidden input so i cant give you any info to fix that.

despite all that, i'm sure someone at some point will say: tables ewww so lets get that one out of the way now.
#3

[eluser]jblack199[/eluser]
Just reread your HTML, i rewrote it from scratch -- try it and see what happens. Apparently, because I havent purchased any software or something I cant post 'links' so change all the f href's to the correct syntax otherwise it really wont work.

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

[eluser]boltsabre[/eluser]
Yeah, I'd imagine it's got to do with putting an input field (in your case the hidden one) inside an anchor tag. Your <a> tag is all over the place, it has no href=""..., it has not 'link text' between the opening and closing <a> tags....

I'm guessing your trying to pass the $item->data_id as an identifier so when the user clicks on the link some action happens, but only for that particular $data_id..??? You'll have to append/concatenate this variable to your href attribute and then in your controller extract it using $this->uri->segment(whatever segment your $data_id is). Or make a new form inside your foreach loop for each item, and use a hidden field to populate this value... I think you may be trying to combine both methods together, and that's where your getting into trouble.
#5

[eluser]Wondering Coder[/eluser]
actually I solved it. Also its not a typo problem in my part. Somehow when I copy paste and posted my code in here, the output changes., haha. Also I think I undestand why it's not throwing the hidden field value to my controller its bcoz I'm not using &lt;form&gt;&lt;/form> just a regular <a></a> link.

So what I did to solve this is by throwing the value in my url. e.g.: <a ></a>'
#6

[eluser]boltsabre[/eluser]
Well yes... if you output a hidden (or any form field for that matter) and it's not inside &lt;form&gt; tags with an action/method then it is not going to do anything!!! HTML 101 ;-)

Glad to hear you got it solved by attaching the value to your anchor tag like I suggested. If this is solved, can you please edit the title to reflect this so others know everything is fixed! Thanks champ.




Theme © iAndrew 2016 - Forum software by © MyBB