PHP help in CodeIgniter

Soldato
Joined
26 Aug 2012
Posts
4,399
Location
North West
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

Code:
<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;

                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

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!
 
Soldato
Joined
8 Oct 2005
Posts
4,185
Location
Midlands, UK
Quite a few options. Could wrap each submit button in a form, set the form action to your required controller and a add a hidden field (user id) for each table row. This hidden id will get posted to your controller. Alternatively, could just set the form action to your controller E.g. /users/verify/123, /users/verify/1234 etc and priocess the post of that.

Another option would be to just use a normal hyperlink that points to your controller with the user id.
 
Soldato
OP
Joined
26 Aug 2012
Posts
4,399
Location
North West
Quite a few options. Could wrap each submit button in a form, set the form action to your required controller and a add a hidden field (user id) for each table row. This hidden id will get posted to your controller. Alternatively, could just set the form action to your controller E.g. /users/verify/123, /users/verify/1234 etc and priocess the post of that.

Another option would be to just use a normal hyperlink that points to your controller with the user id.

Thanks, second one is probably the easiest method to implement!
 
Associate
Joined
10 Nov 2013
Posts
1,808
Any operation that manipulates data on the server should be done by posting to the server, not performing a GET. Of the options suarve suggested, the first would be preferable.
 
Back
Top Bottom