Sandeep Londhe
Sandeep Londhe

Reputation: 405

PHP CodeIgniter not posting data from table row

I working with PHP CodeIgniter, I want to post the table row, and get the post values in the controller, the controller is working fine but I am not able to post the values.

I create It's controller successfully the only part is that the values are not getting posted.

I want to post values from a single row of the table, not all the rows.

Here is my form code

<div class="row" id="attendance_list">
    <div class="col-sm-offset-3 col-md-6">
        <table class="table table-bordered">

            <thead>
                <tr>
                    <td><?php echo get_phrase('student_id');?></td>
                    <td><?php echo get_phrase('roll');?></td>
                    <td><?php echo get_phrase('name');?></td>
                    <td><?php echo get_phrase('Theory');?></td>
                    <td><?php echo get_phrase('Practical');?></td>
                    <td><?php echo get_phrase('Send Remarks');?></td>
                    <td><?php echo get_phrase('SEND');?></td>
                </tr>
            </thead>
            <tbody>

                <?php echo form_open(base_url() . 'index.php?admin/send_message_to_perent/create' , array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?>


                <?php 
                    $students   =   $this->db->get_where('student' , array('class_id'=>$class_id))->result_array();
                        foreach($students as $row):


                        <tr class="gradeA">

                            <td>

                            <input type="hidden" name="student_id" value="<?php echo $row['student_id'];?>">
                            <?php echo $row['student_id'];?>


                            </td>


                            <td>
                            <?php echo $row['roll'];?>                      

                            </td>

                            <td><?php echo $row['name'];?></td>


                 <!-- For Theory Attendance-->



                            <td>

                            <?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % 

                            </td>       





                 <!-- For Practical Attendance-->



                            <td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td>



                    <td>

                            <input type="textarea" name="notice" value="<?php echo $row['notice'];?>">




                    </td>

                <td>

                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-5">
                                <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button>
                            </div>
                        </div>



                </td>


                        </tr>
                    <?php endforeach;?>



           </form>          
            </tbody>

        </table>
    </div>
</div>

Upvotes: 0

Views: 1175

Answers (1)

Johnish
Johnish

Reputation: 81

There are several things wrong with this. Since Codeigniter is an MVC framework you should be following the standards for it. https://softwareengineering.stackexchange.com/questions/127624/what-is-mvc-really

Notably this shouldn't have a database call inside of a view. The database call should be in the module and passed in to the view from the controller.

Other items: Forgot to close ?> after the foreach ($students as $row) : This is an invalid input type <input type="textarea"

I didn't really understand the question fully and I wasn't sure if you wanted a new form for each row with it's own submit button of you wanted one big form with one submit button.

The answer I am giving is assuming you wanted one big form with one submit button.

<?php echo form_open(base_url() . 'index.php?admin/send_message_to_perent/create' , array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?>
<?php
foreach ($students as $row) :
?>
        <tr class="gradeA">
            <td>
            <input type="hidden" name="student_id[]" value="<?php echo $row['student_id'];?>">
            <?php echo $row['student_id']; ?>
            </td>
            <td><?php echo $row['roll'];?>                      
            </td>
            <td><?php echo $row['name'];?></td>
<!-- For Theory Attendance-->
<td><?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % 
</td>
<!-- For Practical Attendance-->
<td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td>
<td><textarea rows="4" cols="50" name="notice[]"><?php echo $row['notice'];?></textarea></td>

</tr>
<?php endforeach;?>
<tr><td colspan="5"><div class="form-group">
        <div class="col-sm-offset-3 col-sm-5">
            <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button>
        </div>
    </div>
    </td>
</tr>
</form>

Here's a form for each row.

<?php
foreach ($students as $row) :
?>
<?php echo form_open(base_url() . 'index.php?
   admin/send_message_to_perent/create' , 
array('class' => 'form-horizontal form-groups-bordered validate','target'=>'_top'));?>
<tr class="gradeA">
    <td>
        <input type="hidden" name="student_id" value="<?php echo $row['student_id'];?>">
        <?php echo $row['student_id']; ?>
    </td>
    <td><?php echo $row['roll'];?></td>
    <td><?php echo $row['name'];?></td>
    <!-- For Theory Attendance-->
    <td><?php echo number_format((float)$theoryPercentage, 0, '.', ''); ?> % </td>
    <!-- For Practical Attendance-->
    <td> <?php echo number_format((float)$practicalPercentage, 0, '.', ''); ?> % </td>
    <td><textarea rows="4" cols="50" name="notice"><?php echo $row['notice'];?></textarea></td>
</tr>
<tr><td colspan="5">
    <div class="form-group">
        <div class="col-sm-offset-3 col-sm-5">
            <button type="submit" class="btn btn-info"><?php echo get_phrase('SEND');?></button>
        </div>
    </div>
    </td>
</tr>
</form>
<?php endforeach;?>

Upvotes: 3

Related Questions