Welcome Guest, Not a member yet? Register   Sign In
Not clear on how to pass radio button values to controller
#1

[eluser]zulubanslee[/eluser]
I'm probably overlooking something stupid.
I know the controller is being called correctly.
Here is my code:

View
Code:
foreach($query->result() as $row)
{
  echo '<tr>'.                                                          
          '<td>&lt;input type="radio" name="author" id="author" value="'.$row-&gt;id.'"/></td>'.                                            
          '<td>'.$row->prefix.'</td>'.                                                                    
          '<td>'.$row->lastname.'</td>'.                                                                    
          '<td>'.$row->firstname.'</td>'.
          '<td>'.$row->middlename.'</td>'.                                                                    
          '<td>'.$row->suffix.'</td>'.
          '<td>'.$row->bio.'</td>'.    
          '<td> NOTES: '.$row->notes.'</td>                                                                                    
         </tr>';                                                                                    
}

And my controller
Code:
function editthisauthor()
{
   $id         = $this->input->post('id');
   $prefix    = $this->input->post('prefix');
   $lastname    = $this->input->post('lastname');
   $firstname    = $this->input->post('firstname');
   $middlename    = $this->input->post('middlename');
   $suffix    = $this->input->post('suffix');
   $notes    = $this->input->post('notes');                
            }
#2

[eluser]Anonymous[/eluser]
This makes no sense, where are the inputs ?
#3

[eluser]Amitabh Roy[/eluser]
You are printing the html content in a controller. It should not be handled that way. Or maybe you made a typo and, the first controller that you mentioned is actually a view.

Radio button values are handled the same way as the other form fields like text, textarea etc. So the following code should work fine, assuming that you have the form tags properly setup.

Code:
$author  = $this->input->post('author');

If you are really printing the html in one controller method and want to post it to another controller method, it would not be a correct implementation of MVC. I would suggest you use views to display the html. How to use views can be found in this section of CI guide Codeigniter views
#4

[eluser]zulubanslee[/eluser]
Sorry I screwed up and said the section of code at the top was the controller when in fact it is the View.
#5

[eluser]zulubanslee[/eluser]
[quote author="Amitabh Roy" date="1308747200"]You are printing the html content in a controller. It should not be handled that way. Or maybe you made a typo and, the first controller that you mentioned is actually a view.

Radio button values are handled the same way as the other form fields like text, textarea etc. So the following code should work fine, assuming that you have the form tags properly setup.

Code:
$author  = $this->input->post('author');

If you are really printing the html in one controller method and want to post it to another controller method, it would not be a correct implementation of MVC. I would suggest you use views to display the html. How to use views can be found in this section of CI guide Codeigniter views[/quote]

thanks you code worked well. I tried that before and I don't know why it didn't work.
#6

[eluser]Amitabh Roy[/eluser]
glad it solved your issue ... Smile




Theme © iAndrew 2016 - Forum software by © MyBB