Placeholder text in form fields

Discussion in 'Templates customization' started by wpdesignlabs, May 6, 2016.

  1. wpdesignlabs

    wpdesignlabs New Member

    Joined:
    Sep 20, 2013
    Messages:
    1
    Hi

    I want to add placeholder text in all the form fields.

    Thanks
    Priyanshu
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Do you want to set label as placeholder? I am afraid there is not easy way to do it. You need to edit file
    amember/application/default/views/_form.phtml
    and replace code
    PHP:
    $renderer = new Am_Form_Renderer_User();
    with
    PHP:
    class Am_Form_Renderer_Custom extends Am_Form_Renderer_User
    {
        public function 
    renderElement(HTML_QuickForm2_Node $element)
        {
            list(
    $_) = $element->getLabel();
            if (
    $_) {
                
    $element->setAttribute('placeholder'$_);
            }
            return 
    parent::renderElement($element);
        }
    }
    $renderer = new Am_Form_Renderer_Custom;
    I suggest to copy this template to your custom theme folder so next upgrade do not override your changes.
    http://www.amember.com/docs/Themes_and_Templates
  3. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    ^^ that kinda works for all fields EXCEPT for the First & Last Name field.

    Why?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    These fields just has not labels so you do not see placeholders.
    You can use the following workaround:
    PHP:
    class Am_Form_Renderer_Custom extends Am_Form_Renderer_User
    {
        public function 
    renderElement(HTML_QuickForm2_Node $element)
        {
            list(
    $_) = $element->getLabel();
            if (
    $element->getName() == 'name_f') {
                
    $_ 'First Name';
            }
            if (
    $element->getName() == 'name_l') {
                
    $_ 'Last Name';
            }
            if (
    $_) {
                
    $element->setAttribute('placeholder'$_);
            }
            return 
    parent::renderElement($element);
        }
    }
    $renderer = new Am_Form_Renderer_Custom;

Share This Page