Welcome Guest, Not a member yet? Register   Sign In
Message: Illegal offset type in isset or empty in form_validation
#1

[eluser]buckboru[/eluser]
I receiving this error when trying to load data into an edit form.
Scenario
Load a table. Select a record from table and load the specific record into form to edit.

Controller snippet.
Code:
function edit_phone($id = false)
    {
        
        $this->form_validation->set_rules('lastname', '', '');
        if (!$id) redirect ('phonelist/list_users');
        
        
        $data['phonelist'] = $this->phone_model->get_phone($id);
        
        $this->load->view('phone_edit',$data);
View snipped
Code:
echo form_open('/phonelist/edit_form/'.$this->uri->segment(3) );

echo form_label('Last Name', 'Last' ).'  ';
$data = array(
                  'name'        => 'lastname',
                  'id'          => 'lastname',
                  'value'       => set_value('lastname', (isset($phonelist['LAST_NAME'])) ? $phonelist['LAST_NAME'] : ''),
                  'maxlength'   => '25',
                  'size'        => '25',
                  'style'       => ''
                  );

                
echo form_input(set_value($data)).'<br />' ;

value of $data prior to the form_input statement.
$data = Array[6]
id = (String:8)lastname
maxlength = (string:2)25
name = (String:8)lastname
size = (string:2)25
style = (string:0)
value = (string:30)Smith

I just can't figure out what the problem is.
I appreciate any help you can provide.

Thanks
#2

[eluser]TheFuzzy0ne[/eluser]
set_value() simply retrieves a value from the $_POST array, or uses the specified default if it doesn't exist.
Code:
echo form_input(set_value($data)).'<br />' ; // Incorrect usage of set_value()!
echo form_input($data).'<br />' ; // Better usage; set_value() not necessary.

That's your problem; set_value() is expecting a string, not an array. It's looking for the specified offset in the $_POST array, but it can't.

Code:
$arr1['test'] = 'test';
$another_array['test'] = 'test';

echo $arr['test']; // Correct usage.
echo $arr['test2']; // Will give a warning, but is still correct.
echo $arr[$another_array]; // Invalid offset type - string expected.

Hope this helps.




Theme © iAndrew 2016 - Forum software by © MyBB