3

I had gone through drupal link which contains something as shown below
https://drupal.org/node/224333

Use '#markup' not '#value' for markup

(Issue) The new default type for items in forms or other structured array data (e.g. node content) passed to drupal_render() is '#type' => 'markup'. In Drupal 6 and earlier, the HTML content was added to the array using the #value attribute. In Drupal 7, this needs to be changed to #markup. This change also applies to those form elements of '#type' => 'item'. This change reduces the confusion between form values and markup and allows the code in drupal_render() to be simplified.

Example 1, from system.admin.inc In Drupal 6:

<?php
  $screenshot = $screenshot ? theme('image', $screenshot, t('Screenshot for %theme theme', array('%theme' => $theme->info['name'])), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');

  $form[$theme->name]['screenshot'] = array('#value' => $screenshot);
?>

In Drupal 7:

<?php
  $screenshot = $screenshot ? theme('image', array('path' => $screenshot, 'alt' => t('Screenshot for %theme theme', array('%theme' => $theme->info['name'])), 'attributes' => array('class' => 'screenshot'))) : t('no screenshot');

  $form[$theme->name]['screenshot'] = array('#markup' => $screenshot);
?>

I have a code in drupal 6 which is as shown below :

$form['in_title'] = array(
  '#type' => 'button',
  '#value' => t('ort'),
  '#executes_submit_callback' => false,
  '#attributes' => array('class' => 'hide-submit-exclude'),
);

I want to convert this code to D7 .
So When and where should I use #markup and #value ?
I just want to know the difference between #markup and #value

2

#markup is

Used to set HTML that will be output on the form.

#value is

Used to set values that cannot be edited by the user. Should NOT be confused with #default_value, which is for form inputs where users can override the default value.

For #value this might include submit buttons, hidden elements, etc. - basically anything that needs a value for the form submission, but where that value should not come from the user.

The only change you need to make in your sample code is to allow for the fact that classes in the attributes array must now be in an array themselves:

$form['in_title'] = array(
  '#type' => 'button',
  '#value' => t('ort'),
  '#executes_submit_callback' => false,
  '#attributes' => array('class' => array('hide-submit-exclude')),
);
| improve this answer | |
  • '#attributes' => array('hide-submit-exclude') is this right? – harshal Aug 8 '13 at 11:47
  • If you want to add hide-submit-exclude="hide-submit-exclude" as an attribute then sure :) Otherwise, just use the code in the answer – Clive Aug 8 '13 at 11:50
  • Pls.correct if I am wrong...................... $form['ort'] = array('#value' => '<div id="rcp-signed-report"></div>',); This is d6 code and since it contains html that will be output to form should I use #markup instead of #value in the D7 drupal code.Am I right? – harshal Aug 8 '13 at 12:01
  • Totally right, yes – Clive Aug 8 '13 at 12:14

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.