1

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: helpers/form_helper.php

Line Number: 522

Here is my view that contains form

        <?php
        // open the form using CI form helper
        echo form_open('loginController', array('id' => 'login'));
        // first input field
        echo "<div>";
        echo form_label('Username', array('for' => 'login_username'));
        echo form_input(array(
            'type' => 'text',
            'name' => 'username',
            'id' => 'login_username',
            'value' => set_value('username')
        ));
        echo "</div>";
        // second input field
        echo "<div>";
        echo form_label('Password', array('for' => 'login_password'));
        echo form_password(array('type' => 'password', 'name' => 'password', 'id' => 'login_password'));
        echo "</div>";
        // submit button
        echo "<div class='submit'>";
        echo form_button(array('type' => 'submit', 'content' => 'Log in'));
        echo "</div>";

        echo "<div class='errors'>";
        // display if incorrect username/password
        if ($this->session->flashdata('login_error'))
            echo 'Incorrect username/password';
        // display if incorrect input data
        echo validation_errors();
        echo "</div>";
        // close the form
        echo form_close();
        ?>

Here is form_helper.php (line 513 to 537) that is mentioned in PHP Error

if ( ! function_exists('form_label'))
{
function form_label($label_text = '', $id = '', $attributes = array())
{

    $label = '<label';

    if ($id != '')
    {
        $label .= " for=\"$id\"";
    }

    if (is_array($attributes) AND count($attributes) > 0)
    {
        foreach ($attributes as $key => $val)
        {
            $label .= ' '.$key.'="'.$val.'"';
        }
    }

    $label .= ">$label_text</label>";

    return $label;
}
}
4
  • $label .= " for=\"$id\""; Commented Jun 17, 2013 at 6:25
  • can u show the code which your are making a call to form_label()? Commented Jun 17, 2013 at 6:26
  • 1
    On line:3 echo form_label('Username', array('for' => 'login_username')); here you passing second parameter as array where it should be string. Commented Jun 17, 2013 at 6:29
  • echo form_label('Password', array('for' => 'login_password')); ? Commented Jun 17, 2013 at 6:31

2 Answers 2

1

Here

echo form_label('Username', array('for' => 'login_username'));

and here

echo form_label('Password', array('for' => 'login_password'));

You are passing an array for the id parameter of the function that should be a string try

echo form_label('Username', "lblUsername", array('for' => 'login_username'));

and

echo form_label('Username', "lblPassword", array('for' => 'login_username'));

Or simply pass null in as the value of the id.

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

Comments

0

You are calling function in wrong way. The 3rd parameter is array but you are passing 2nd parameter as array.

Use below kind of function call for all form_label.

echo form_label('Username', 'Username',array('for' => 'login_username'));
                          ^^^^^^^^^^^^

Function definition

function form_label($label_text = '', $id = '', $attributes = array())

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.