Reputation: 13
So I'm pretty retarded at this sort of stuff, this is my first attempt at coding something so here goes:
This is in my view:
<?php
echo form_open();
echo form_radio('name1', '1'). " 1";
echo form_radio('name1', '2'). " 2";
echo form_radio('name1', '3'). " 3";
echo form_radio('name2', '1'). " 1";
echo form_radio('name2', '2'). " 2";
echo form_radio('name2', '3'). " 3";
echo form_radio('name3', '1'). " 1";
echo form_radio('name3', '2'). " 2";
echo form_radio('name3', '3'). " 3";
echo form_submit('vote', 'Submit!');
echo form_close();
?>
This is in my controller:
if ($this->input->post('vote')) {
$this->My_model->do_something();
}
This is the final bit i need done for my little script, i want 3 different variables from the radio box's to my controller then my model but I'm not quite sure how to do it and CI just confuses me sometimes.
Help!
Upvotes: 0
Views: 10947
Reputation: 227190
$name1 = $this->input->post('name1');
$name2 = $this->input->post('name2');
$name3 = $this->input->post('name3');
if ($this->input->post('vote')) {
$this->My_model->do_something($name1, $name2, $name3);
}
With radio buttons, if there are multiple with the same name, only one of that name can be selected. The above 3 lines should return a 1, 2, or 3 for each of the 3 sets of radio buttons.
EDIT: To check for duplicate values in PHP, you can use array_unique
.
$names = array($name1, $name2, $name3);
$uniqueNames = array_unique($names);
if($names == $uniqueNames){
// No duplicate values
}
else{
// Duplicate values
}
Upvotes: 4
Reputation: 1110
In controller:
$btnNo1 = $this->input->post('name1');
$btnNo2 = $this->input->post('name2');
$btnNo3 = $this->input->post('name3');
$this->load->model('My_model');
$this->My_model->do_something($btnNo1,$btnNo2,$btnNo3);
In model:
class My_model extends Model{
function My_model(){
parent::Model();
}
public function do_something($btn1,$btn2,$btn3){
//do some stuff with you btn values
}
}
Upvotes: 0