Expression Engine: adding placeholder to text fields
Safecracker has been a huge leap forward in managing front-end “stand alone entry forms” (SAEFs). One feature I was looking for is to simply add the attribute “placeholder” in each of the standard text input fields.
With a simple tweak to the text fieldtype file, this was an easy add: (EE version 2.3.1)
- In /(your system folder)/expressionengine/fieldtypes/text/ft.text.php
- Make the following modification:
Before Modification:
function display_field($data)
{
$type = (isset($this->settings['field_content_type'])) ? $this->settings['field_content_type'] : 'all';
$data = $this->_format_number($data, $type);
return form_input(array(
'name' => $this->field_name,
'id' => $this->field_name,
'value' => $data,
'dir' => $this->settings['field_text_direction'],
'maxlength' => $this->settings['field_maxl'],
'field_content_type' => $type
));
}
After Modification
function display_field($data)
{
$type = (isset($this->settings['field_content_type'])) ? $this->settings['field_content_type'] : 'all';
$data = $this->_format_number($data, $type);
return form_input(array(
'name' => $this->field_name,
'id' => $this->field_name,
'value' => $data,
'dir' => $this->settings['field_text_direction'],
'maxlength' => $this->settings['field_maxl'],
'placeholder' => $this->settings['field_label'], // this line added to show placeholder text
'field_content_type' => $type
));
}
PROS:
- simple fix
- places placeholder text in all text fields added by safecracker
CONS:
- places placeholder text in ALL text fields (no function to only display if desired, etc…)
