Hey all, how can I use the placeholder tag in CodeIgniter's form_input() helper function?
Thanks :)
Do you mean the placeholder attribute (not tag)? form_input() takes a third parameter with additional attributes.
$opts = 'placeholder="Username"';
form_input('username', '', $opts);
Or you can pass form_input() an array.
form_input(array(
'name' => 'username',
'value' => '',
'placeholder' => 'Username',
));
CodeIgniter Form Helper
The Codeigniter user guide linked to by Rocket indicates that attributes other than name and value are passed to form_input() as an array:
$data = array(
'name' => 'username',
'id' => 'username',
'value' => 'johndoe',
'maxlength' => '100',
);
echo form_input($data);
// Would produce:
<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" />
To expand on Rocket's answer, passing 'placeholder'=>'my_placeholder' into that array should produce the placeholder attribute.
$data = array(
'name' => 'username',
'id' => 'username',
'value' => 'johndoe',
'maxlength' => '100',
'size' => '50',
'style' => 'width:50%',
'placeholder' => 'my_placeholder'
);
echo form_input($data);
Keep in mind, the placeholder attr is very new and not supported in all browsers. Check out this article at html center for html5, jQuery, and pure javascript ways to accomplish placeholders
Codeigniter form placeholder for IE6, IE7 and IE8
echo form_input(array(
'name' => 'stackoverflow',
'value' => 'yourplaceholder',
'placeholder' => 'yourplaceholder',
'onclick' => 'if(this.value == \'yourplaceholder\') this.value = \'\'', //IE6 IE7 IE8
'onblur' => 'if(this.value == \'\') this.value = \'yourplaceholder\'' //IE6 IE7 IE8
));
you can set placeholder like this
echo form_input('username','','placeholder=username');
this will look like this
<input type='text' name='username' placeholder='username'/>
Related
In my project, I got many forms, so I've decided to specify each one with an iscription field, for exemple: Kids' form => <input = 'hidden' name = 'inscripted_in' value = 'kids'>. I want to set each one with a default value, but whenever I sign in, I get this error message:
SQLSTATE[HY000]: General error: 1364 Field 'inscripted_at' doesn't have a default value
Although when I go to Laravel Debug, I still get the inserted constant value, what's the problem?
This is one of my forms
<div class="InputBox">
<input type="hidden" name="inscripted_at" value="Adults">
<input type="hidden" name="status" value="pending">
</div>
my controller:
public function store(Request $req)
{
$this->validate($req,[
'name' => 'required|max:120',
'surname' => 'required|max:120',
'job' => 'required|max:120',
'day' => 'required',
'month' => 'required',
'year' => 'required',
'hobby' => 'required|max:120',
'help' => 'required|max:120',
'place' => 'required|max:120',
'residence' => 'required|max:120',
'email' => 'required|email|unique:users',
'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'scholar_year' => 'required|max:120',
'tel' => 'required|regex:/(05)[0-9]{8}/',
]);
Chababounauser::create($req->all());
return redirect()->route('chababounausers.index')
->with('success','chababouna User inserted successfully.');
}
Check the fillable property of the Chababounauser model.
P.S.: Please, don't put spaces in HTML between attribute name and it's value.
Isn't 'inscripted_at' a default column in the database giving the date of inscription ? If so, you can't default a value to that kind of output.
Hello friends I need make a Textarea with Laravel Collective, regulary I use:
<textarea id="txt" name="txt" maxlength="1900" class="form-control" rows=1" onkeypress="return nameFunction(event);">My text</textarea>
How to create a textarea wiht Laravel Collective?
Try like this:
Form::textarea('My text', null, [
'class' => 'form-control',
'rows' => 1,
'name' => 'txt',
'id' => 'txt',
'onkeypress' => "return nameFunction(event);"
])
I wanted to fetch the selected value from the database and display it in codeigniter form_dropdown() function but it displays wrong.
Controller:
$type = array(
'options' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
'attributes' => array(
'class' => 'form-control'
)
);
View:
<?php echo form_dropdown('type', $type['options'],'', $type['attributes']) ?>
The Screenshot
Try the below code:
Controller:
$this->data['type'] = array(
'name' => 'type_value',
'attributes' => 'class="form-control"',
'value' => (isset($database_type_value) && trim($database_type_value)) ? $database_type_value: $this->input->post('type_value',TRUE), //$database_type_value - value from database
'options_list' => array(
'section' => 'Section',
'transaction' => 'Transaction',
'document' => 'Document'
),
);
View:
<?php echo form_dropdown($type['name'],$type['options_list'],$type['value'],$type['attributes']);?>
Problem in dependent dropdowns when editing in my yii application.
While editing, the drop downs are not automatically selected.
In my view,
array('class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{update} {view} {delete}',
'htmlOptions' => array('width' => '20%'),
'buttons' => array(
'update' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-pencil'),
),
'view' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-eye-open'),
),
'delete' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-remove'),
),
),
),
<div class="form-group">
<label for="reg_input" class="req">Course</label>
<?php
$course = CHtml::listData(Course::model()->findAll(), 'courseid', 'course_name');
echo CHtml::activeDropDownList($model, 'courseid', $course, array(
'empty' => 'Select Course', 'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchbatch'),
'update' => '#' . CHtml::activeId($model, 'batchid'))));
?>
<?php echo $form->error($model, 'courseid', array('class' => 'school_val_error')); ?>
</div>
<div class="form-group">
<label for="reg_input" class="req">Batch</label>
<?php
$batch = CHtml::listData(Batch::model()->findAll(), 'batchid', 'batch_name');
echo $form->dropDownList($model, 'batchid', $batch, array('prompt' => 'Select Batch',
'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchsubject'),
'update' => '#' . CHtml::activeId($model, 'subjectid'))));
echo $form->error($model, 'batchid', array('class' => 'school_val_error'));
?>
</div>
Second dropdown get the data, to change of first dropdown. At this condition the dropdown will not be selected automatically. Because when editing, that value is not there. So I fixed this problem, my code is above this.
I have tried to limit number of rows in textarea to 4 but its giving error
Message: Array to string conversion
this is my code of textarea using helper class
$textarea_options = array('class' => 'form-control','rows' => 4, 'cols' => 40);
echo form_textarea('vc_desc', set_value('vc_desc'), $textarea_options);
setup a $data array instead with all the options
$data = array(
'name' => 'vc_desc',
'id' => 'vc_desc',
'value' => set_value('vc_desc'),
'rows' => '50',
'cols' => '10',
'style' => 'width:50%',
'class' => 'form-control'
);
echo form_textarea($data);
Use rows and cols to get change the height and length of text area in code ignitor.
$data = array('name' => 'SupAddress','value' =>set_value('SupAddress'), 'id'=>'SupAddress', 'class' => 'form-control' ,'readonly' => 'true' ,'rows' => '3', 'cols' => '40');
echo Form_textarea($data);