Welcome Guest, Not a member yet? Register   Sign In
How to get posted value in multiple select box and how to validate it
#1

[eluser]shankar ganesh[/eluser]
The below code for controller
Code:
<?php
class All_controls extends Controller
{
    function All_controls()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        $this->load->library("validation");
    }
    function index()
    {
        $data['location'] = array(""=>"Select","1"=>"Coimbatore","2"=>"Chennai","3"=>"Madurai");
        $data['loc_select'] = array("1");
        $data['parttime'] = array('name'=>'parttime','id' =>'parttime','value'=> 'part','checked'=> TRUE);
        $data['fulltime'] = array('name'=>'fulltime','id' =>'fulltime','value'=> 'full','checked'=>FALSE);
        $data['male_gender'] = array('name'=>'gender','id' =>'gender_male','value'=> 'Male','checked'=> TRUE);
        $data['female_gender'] = array('name'=>'gender','id' =>'gender_female','value'=> 'Female','checked'=>FALSE);
        $data['department'] = array(""=>"Select","1"=>"EIT","2"=>"Offshore","3"=>"Testing","4"=>"Marketing");
        $data['dept_select'] = array("1","2");
        $this->load->view("controls",$data);
    }
    function validate()
    {
        echo '<pre>';
        print_r($_POST);

        echo "<br/>";
        $this->input->post('department');

        echo "Validated";
    }
}
?&gt;

The below code for view

Code:
&lt;html&gt;
&lt;body&gt;
&lt;?php echo form_open('all_controls/validate');?&gt;
<table border="0">
    <tr>
        <td>Name</td>
        <td>&lt;input type="text" value="" name="name" id="name"&gt;&lt;/td>
    </tr>
    <tr>
        <td>Gender</td>
        <td>&lt;?php echo form_radio($male_gender);?&gt;Male &nbsp;&nbsp;&lt;?php echo form_radio($female_gender);?&gt;Female</td>
    </tr>
    <tr>
        <td>Job type</td>
        <td>&lt;?php echo form_checkbox($parttime);?&gt;Part Time &nbsp;&nbsp;&lt;?php echo form_checkbox($fulltime);?&gt;Full Time</td>
    </tr>
    <tr>
        <td>Location</td>
        <td>&lt;?php echo form_dropdown('loaction', $location, $loc_select,'id=location');?&gt;</td>
    </tr>
    <tr>
        <td>Department</td>
        <td>&lt;?php echo form_dropdown('department', $department, $dept_select,'id=department');?&gt;</td>
    </tr>
    <tr>
        <td></td>
        <td>&lt;input type="submit" value="Submit" name="sub" id="sub"&gt;&lt;/td>
    </tr>
</table>


&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]Dennis Rasmussen[/eluser]
What error do you get?
Nothing wrong with your code.
Otherwise be more clear about your problem.

For validation you could use the form_validation library.




Theme © iAndrew 2016 - Forum software by © MyBB