0

form_checkbox is not working in Php (Codeigniter).

<div class='checkbox'>
    <?php
    echo form_checkbox(array(
        'name' => 'remember',
        'id' => 'remember',
        'value' => 'Remember Me',
        'checked' => FALSE,
    ));
    ?>
</div>

I have to print the label with checkbox.

2 Answers 2

1

First, you should be sure that you have loaded the file helper? Load file helper something like this :

$this->load->helper('form');

Below code for produce checkbox:

$data = array(
    'name'          => 'newsletter',
     'id'            => 'newsletter',
     'value'         => 'accept',
     'checked'       => TRUE,
     'style'         => 'margin:10px'
);
echo form_label('Checkboc Label', 'newsletter');
// Would produce:  <label for="newsletter">What is your Name</label>
echo form_checkbox($data);
Sign up to request clarification or add additional context in comments.

4 Comments

I tried and its not working. The label is not printing.
I have update answer please check use code for display label : <?php echo form_label('Checkboc Label', 'newsletter');?>
Yes Now its working fine. <div class='checkbox'> <?php echo form_checkbox(array( 'name' => 'remember', 'id' => 'remember', 'value' => 'REMEMBER ME', 'checked' => FALSE, 'style' => 'margin:1px' )).form_label('REMEMBER ME','remember'); ?> </div>
@bhuvana If it is working correctly so pleaee accepr the answer so help others too.
0

First, you need to load form helper and then you need to concat your label string before the form_checkbox() like below

<div class='checkbox'>
    <?php
    echo 'Remember Me '.form_checkbox(array(
        'name' => 'remember',
        'id' => 'remember',
        'value' => '1',
        'checked' => FALSE,
    ));
    ?>
</div>

2 Comments

Thank you its working but I concatenated after the form_checkbox. <div class='checkbox'> <?php $data = array( 'name' => 'remember', 'id' => 'remember', 'value' => 'REMEMBER ME', 'checked' => FALSE, //'style' => 'margin:10px' ); echo form_checkbox($data)."\r\r"."REMEMBER ME"; ?> </div>
your welcome, please accept the answer if it helps you so others can get easy help

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.