简体   繁体   中英

Issue passing data from view to controller in codeigniter

I am using the CodeIgniter framework to build a site.

I currently have a view which prints all the unverified members into a table and also puts a button for each member which can be clicked to Verify that account.

Here is the code for the view

<h2>Admin Control Panel</h2>
<?php
/*
 * First Output Members to be verified in tables
 */

//check if there is actually any data to print first.
    echo ("<h3> Members to be Verified</h3>");
    if(empty($unverified_members))
    {
        echo "<h4>There are currently no members to be verified </h4>";

    }
    else
    {
    $count_unverified_members=count($unverified_members);

    echo "<table border='1'>";

    //print table headers
    echo <<<HTML
    <th><div align ="center">ID Number</div></th>
    <th><div align ="center">Username</div></th>
    <th><div align ="center">E-Mail Address</div></th>
    <th><div align ="center">Verify Account</div></th>
HTML;

    for($arr_counter=0;$arr_counter<$count_unverified_members;$arr_counter++)
        {
            $current_member_id=$unverified_members[$arr_counter]->member_id;
            $current_username=$unverified_members[$arr_counter]->username;
            $current_email=$unverified_members[$arr_counter]->email;

            //now print values
            echo<<< HTML
            <tr>
            <td><div align ="center">$current_member_id</div></td>
            <td><div align ="center">$current_username</div></td>
            <td><div align ="center">$current_email</div></td>
            <td><form action="Verify" method="post"><div align ="center"><input type="submit" value="Verify" /></div></form></td>
            </tr>

HTML;
        }
    echo "</table><br><br>";

    }
?>

I am trying to pass to my controller the user to be verified.

In the second heredoc I have this bit of code

<td><form action="Verify" method="post"><div align ="center"><input type="submit" value="Verify" /></div></form></td>

I want to for that user submit the member_id of that user and also a flag of some description which would mean that the user with that member_id needs to be verified.

So in essence

Print users needing verfication into table->click verify for particular user to be verified->pass to controller the user selected and a flag to indicate that user can be verified-> controller passes info to model-> model sets flag in the Database saying that user can be verified->model moves all users with that flag set to the verified_users table.

I can do all the controller/model bits myself. It's just getting the data from the view to the controller I am struggling with.

Any help would me much appreciated! If any of it makes sense!

you just need a hidden form field to send the ID -- using your code

<td><form action="members/verify" method="post">
<input type="hidden" name="memberid" value="<?php echo $current_member_id ?>" />
<div align ="center"><input type="submit" value="Verify" /></div>
</form>
</td>

in your controller you can then get the value of member id from the form like

$memberid = $this->input->post( 'memberid', TRUE ) ; 

important point -- note that for this example i wrote the form action as "members/verify" . that means it will go to a controller named members, and the method named verify.

when you have time check out codeigniters table class - it can really help http://ellislab.com/codeigniter/user-guide/libraries/table.html

and the tutorial is a good reference for common tasks http://ellislab.com/codeigniter/user-guide/tutorial/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM