Placeholders in Registation

GK User
Tue Sep 18, 2012 12:13 pm
Hi i am using gk register module and i am searching for this php lines in order to put placeholders

<input type="text" name="jform[name]" id="jform_name" value="" class="required invalid" size="30" aria-required="true" required="required" aria-invalid="true">

Can you please tell me where to find them ?
Thank you
User avatar
Expert Boarder

GK User
Tue Sep 18, 2012 12:27 pm
Those lines are not hard coded, they are generated on the fly from registration.xml.
Located here: components/com_users/models/forms/registration.xml

See you around...
User avatar
Platinum Boarder

GK User
Tue Sep 18, 2012 1:04 pm
Thank you for the reply
do you know hot to put placeholder in xml file?

i try this but not work
Code: Select all
<field name="name" type="text"
         description="COM_USERS_REGISTER_NAME_DESC"
         filter="string"
         label="COM_USERS_REGISTER_NAME_LABEL"
         message="COM_USERS_REGISTER_NAME_MESSAGE"
         required="true"
         size="30"
         [color=#FF0000]placeholder="Name"[/color]
      />

Why is that not working?
Thank you
User avatar
Expert Boarder

GK User
Tue Sep 18, 2012 1:34 pm
What you write below is a request to joomla to process that for you. There is no such field parameter called "placeholder" so obviously there is no output.

Actual core code is inside below location. This is only valid for text type field. If you need "placeholder" for other fields you would have to edit them as well similar to my example below. See Fields folder for other field types.

Code: Select all
/libraries/joomla/form/fields/text.php

We need to add "placeholder" in to these templates so if there is request from xml file joomla will process it.
So find below line.
Code: Select all
$disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';

Add our code after it which is below
Code: Select all
$placeholder = $this->element['placeholder'] ? ' placeholder="' . $this->element['placeholder'] . '"' : '';

Find following code
Code: Select all
      return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
         . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $onchange . $maxLength . '/>';

We now add $placeholder in to the mix so it gets processed. Replace above with below code or simply add $placeholder.
Code: Select all
      return '<input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
         . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $placeholder . $readonly . $onchange . $maxLength . '/>';


So now joomla will process your request. See below template when adding fields. Remove information lines so it doesn't cause errors.

Code: Select all
      <field name="myfieldname" type="text" // Fieldname must be unique name.
         class="validate-username" // optional for css class if you want to use
         description="COM_USERS_DESIRED_USERNAME" // You can enter a language string or simply write your own lines inside quotes.
         label="COM_USERS_REGISTER_USERNAME_LABEL" // what is shown on display. Use language string or write your own lines inside quotes.
         message="COM_USERS_REGISTER_USERNAME_MESSAGE"
         required="true" // required or not field true / false
         size="30" // size of field box
         placeholder="Name"

      />


See you around...
User avatar
Platinum Boarder

GK User
Tue Sep 18, 2012 3:03 pm
Any help here please?
User avatar
Expert Boarder

GK User
Tue Sep 18, 2012 3:27 pm
Already posted the solution, what you need help with ?
User avatar
Platinum Boarder

GK User
Tue Sep 18, 2012 5:42 pm
I am sorry i didnt see your answer,i will check it,
Thank you very much
User avatar
Expert Boarder

GK User
Tue Sep 18, 2012 5:52 pm
Thank you so much ,
it works perfect
User avatar
Expert Boarder

GK User
Tue Sep 18, 2012 5:58 pm
No problem at all, just make sure to note this somewhere in case you update joomla as you will loose changes.

See you around...
User avatar
Platinum Boarder


cron