Welcome Guest, Not a member yet? Register   Sign In
Code Improvements & Validation
#1

[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
&lt;html&gt;
&lt;body&gt;
&lt;?php $groups = array('fruit'=>'Fruits', 'reptile'=>'Reptile', 'panthera'=>'Panthera');?&gt;
&lt;?php $match = array('Make a Pick','leopard'=>'Leopard','pineapple'=>'Pineapple','cobra'=>'Cobra');?&gt;
    
Select Values coming from db
    &lt;?php echo form_open('/web/select_validate'); ?&gt;
     <table> //Visuals @ http://jsfiddle.net/cyCRt/1/
        <tr>
            <td>&lt;?php echo form_dropdown('group_1',$groups);?&gt;</td>
            <td>&lt;?php echo form_dropdown('match_1',$match);?&gt;</td>
        </tr>
        <tr>
            <td>&lt;?php echo form_dropdown('group_2',$groups);?&gt;</td>
            <td>&lt;?php echo form_dropdown('match_2',$match);?&gt;</td>
        </tr>
        <tr>
            <td>&lt;?php echo form_dropdown('group_3',$groups);?&gt;</td>
            <td>&lt;?php echo form_dropdown('match_3',$match);?&gt;</td>
        </tr>
    </table>
    &lt;?php echo form_submit('submit','Enter Selection');?&gt;
    &lt;?php echo form_close(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;
All answers are welcomed. The many improvements the more I learn. Thank You


Messages In This Thread
Code Improvements & Validation - by El Forum - 06-17-2012, 10:53 PM
Code Improvements & Validation - by El Forum - 06-17-2012, 10:55 PM
Code Improvements & Validation - by El Forum - 06-17-2012, 10:57 PM
Code Improvements & Validation - by El Forum - 06-17-2012, 11:07 PM
Code Improvements & Validation - by El Forum - 06-17-2012, 11:30 PM



Theme © iAndrew 2016 - Forum software by © MyBB