1

In my login form, custom layout fields are displayed by the $field->input variable. Unfortunately, those fields are displayed without the placeholder attribute.

Is there any way to add this attribute to the field which is displayed by variable above?

<?php foreach ($this->form->getFieldset($fieldset->name) as $name => $field) : ?>
    <?php if ($field->hidden === false) : ?>
        <div class="sc-group">
            <?php echo $field->input; ?>
        </div>
    <?php endif; ?>
<?php endforeach; ?>
1

I believe that hint is the attribute you're looking for:

<field name="name"
       label="Name"
       type="text"
       required="true"
       hint="Placeholder Text"
       default=""
/>
1

You need to follow below steps

  1. Go to components/com_yourcomponent/models/forms
  2. Find out the xml file which loads that form.
  3. Find the fields where you want to add the place holder text.
  4. Use hint attribute:<field name="field_name" label="Field Label" type="text" hint="Placeholder Text"/>
0

you can add a hint field in your xlm or you can add a hint value on the fly in your code here : $field->hint = some text;

<?php foreach ($this->form->getFieldset($fieldset->name) as $name => $field) : 
    $field->hint = JText::_('COM_NAME_FORM_HINT_' . strtoupper($field->fieldname));?>
    <?php if ($field->hidden === false) : ?>
        <div class="sc-group">
            <?php echo $field->input; ?>
        </div>
    <?php endif; ?>
<?php endforeach; ?>
  • Please improve your answer to explain how your script works and why it is a good idea. It looks like you merely added one line of code -- please edit your answer to tell us why. A working solution is just the beginning of a "good post". Please be generous with your knowledge. Endeavour to educate/empower the the person who asked the question as well as thousands of future researchers. – mickmackusa Aug 4 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.