Strange behavior with title field I have a strange behavior (or at least this is what I think) I have two form elements. Both are required, in the first (First Name) I want to have a required field so I use '#required' =&gt; TRUE and '#required' =&gt; TRUE in the second I don't use this properties to says that the field is required, I just add this line to the title '&lt;span class="form-required" title="' . t('This field is required.') . '"&gt;*&lt;/span&gt;'. The problem is that the output of the first element is "First name " (with space at the end) and in the second element the output is "Last name" (without space at the end). See the code and the picture with the output code.

Is this a normal behavior or I missing something here?

  $form['general']['group-1']['prenom'] = array(
    '#prefix' =&gt; '&lt;div class="item"&gt;',
    '#title' =&gt; t('First name'),
    '#id' =&gt; 'cf-1',
    '#type' =&gt; 'textfield',
    '#required' =&gt; TRUE,
    '#attributes' =&gt; array('required' =&gt; 'required'),
    '#suffix' =&gt; '&lt;/div&gt;',
  );

  $form['general']['group-1']['nom'] = array(
    '#prefix' =&gt; '&lt;div class="item"&gt;',
    '#title' =&gt; t('Last name') . '&lt;span class="form-required" title="' . t('This field is required.') . '"&gt;*&lt;/span&gt;',
    '#id' =&gt; 'cf-2',
    '#type' =&gt; 'textfield',
    '#suffix' =&gt; '&lt;/div&gt;',
  );


The HTML code:
Works as designed imho.

The markup of the first is generated by the form element/Drupal. By default Drupal has a space between the field title and the asterisk. That's just how it was designed. 

The second time you tell the form what to add - exactly what to add. Drupal wont add a space for you, as you may not always want a space between your custom wrapper and the title. (In most cases you probably don't.)

If it is important to remove the space you can overwrite theme_form_element() in your theme. Check the mid to late replies (starting with kkatusic) in this thread: How to remove asterisks from required fields?

Is there a reason why you would want to mark a field required if it isn't a required field?