0

i have this code in codeigniter (section of form in codeigniter controller) :

$this->data['SalaryType'] = array(
    'name' => 'SalaryType',
    'id' => 'SalaryType',
    'type' => 'text',
    'value' => $this->form_validation->set_value('SalaryType'),
);
$this->data['DefaultSalary'] = array(
   'name' => 'DefaultSalary',
   'id' => 'DefaultSalary',
   'type' => 'text',
   'value' => $this->form_validation->set_value('DefaultSalary'),
);
$this->data['Salary_options'] = array(
    'language' => 'monthly',
    'world' => 'world'
);

(section of form in codeigniter view) :

  <p>
        Salary Type: <br />
        <?php echo form_dropdown($SalaryType,$Salary_options,'monthly');?>
  </p>

  <p>
        Default Salary: <br />
        <?php echo form_input($DefaultSalary);?>
  </p>

and i want use dropdown value but form send input value alone , and i can't access to dropdown value.
i check with print_r($_POST); but in post array observation 'DefaultSalary'.

4
  • 1
    May be your name attr of the drop down is not setting Commented Feb 21, 2013 at 8:38
  • thanks yes my correct code is : 'form_dropdown('SalaryType',$Salary_options,'monthly');' Commented Feb 21, 2013 at 8:43
  • hey can i add id to my dropdown ? Commented Feb 21, 2013 at 8:43
  • if my comment solved your problem so kindly accpet my answer and give a vote upp :-) Commented Feb 21, 2013 at 11:08

2 Answers 2

1

You have initialized dropdown in wrong way

<?php echo form_dropdown($SalaryType,$Salary_options,'monthly');?>

use instead

<?php echo form_dropdown('DefaultSalary',$Salary_options,'language');?>

1st parameter is the name of the control

2nd parameter is the options array ->which is correct

3rd parameter is the selected index from the options array not value that can be in your case 'language' instead of 'monthly'

read form_helper

And you will be able to access it using $this->input->post('DefaultSalary'); and it will return the value of the option selected

Sign up to request clarification or add additional context in comments.

Comments

1

May be your name attr of the drop down is not setting... For adding id to form_drop down you can try this..

form_dropdown('country', $options_array, '1','id="select_id"')

Note : this is not tested.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.