Solved

using hook_element_info() to add a placeholder to a form label

Posted on 2013-12-12
4
686 Views
Last Modified: 2014-01-03
Hi.

I am trying to add a placeholder to the date field by using hook_element_info_alter(). There are really few examples of how to do this to add a placeholder, but for some reason it is not working. This is what I am doing:

/**
 * Implementation of hook_element_info_alter().
 */
function customize_register_form_element_info_alter(&$type) {
  if (isset($type['text'])) {
    $type['text']['#process'][] = 'customize_register_form_text';
  }
}

/**
 * Function for editing label.
 */
function customize_register_form_process_text($element) {
  if ($_GET['q'] == 'user/register') {
    if ($element['#array_parents'][0] == 'account') {
      $element['user_user_form_group_user_birth']['#attributes']['placeholder'] = t('00/00/0000');
    }
  }
  return $element;
}


Could you please help me?

Thanks in advance,

Winter
0
Comment
Question by:glepiza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:darren-w-
ID: 39717176
Perhaps a better way of going about this is to hook into the form and set the placeholder marker?


useing this module: https://drupal.org/project/placeholder


customize_register_form_alter(&$form, &$form_state, $form_id){
$form['your formfield']['#placeholder'] = t('00/00/0000');
}

Open in new window

0
 

Author Comment

by:glepiza
ID: 39717232
thanks Darren,

For some reason I can´t get it to work, it seems I am using the wrong form field…. please take a look at the screenshot I took to show you the source code and see what I am doing wrong. the form field is suppose to be the name attribute right?

Thanks again,
Captura-de-pantalla-2013-12-13-a.png
0
 
LVL 13

Accepted Solution

by:
darren-w- earned 500 total points
ID: 39717241
Hi,

If you can do a print_r/dpm on the $form element this will show its structure.

I suspect the format should be something like

$form['field_date_of_birth'][LANGUAGE_NONE]['#placeholder']= t('00/00/0000'); in line 2 above
0
 

Author Closing Comment

by:glepiza
ID: 39753915
So sorry, I forgot to close this question. Thanks for your answer!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question