[eluser]blue.sky[/eluser]
I have two questions:
1. Improving my code, especially allowing user selections in any order. At the moment even if values were correctly matched the order of selection matters.
2. Please include any necessary input validations. Dropdown list values are from the db.
Code:
public function select() {
$this->load->view('select_view'); // view below
}
public function select_validate() {
if($this->input->post(NULL,TRUE)) {
$group1 = $this->input->post('group_1');
$group2 = $this->input->post('group_2');
$group3 = $this->input->post('group_3');
$match1 = $this->input->post('match_1');
$match2 = $this->input->post('match_2');
$match3 = $this->input->post('match_3');
}
if(($group1 == 'fruit' & $match1 == 'pineapple')&
($group2 == 'reptile' & $match2 == 'cobra')&
($group3 == 'panthera' & $match3 == 'leopard')) {
echo "Correct<br />";
} else {
echo "Wrong<br />";
}
}
Code:
// select_view.php
<html>
<body>
<?php $groups = array('fruit'=>'Fruits', 'reptile'=>'Reptile', 'panthera'=>'Panthera');?>
<?php $match = array('Make a Pick','leopard'=>'Leopard','pineapple'=>'Pineapple','cobra'=>'Cobra');?>
Select Values coming from db
<?php echo form_open('/web/select_validate'); ?>
<table> //Visuals @ http://jsfiddle.net/cyCRt/1/
<tr>
<td><?php echo form_dropdown('group_1',$groups);?></td>
<td><?php echo form_dropdown('match_1',$match);?></td>
</tr>
<tr>
<td><?php echo form_dropdown('group_2',$groups);?></td>
<td><?php echo form_dropdown('match_2',$match);?></td>
</tr>
<tr>
<td><?php echo form_dropdown('group_3',$groups);?></td>
<td><?php echo form_dropdown('match_3',$match);?></td>
</tr>
</table>
<?php echo form_submit('submit','Enter Selection');?>
<?php echo form_close(); ?>
</body>
</html>
All answers are welcomed. The many improvements the more I learn. Thank You