Drupal Form manipulation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. RENDER ONLY 1 FIELD
  2. <?php print drupal_render($form['group_company']['field_street']['0']['value']); ?>
  3. RENDER A GROUP OF FIELDS
  4. You don't need to render fields in group one by one, just enter this code to render all fields in a group:
  5. <?php print drupal_render($form['group_company']); ?>
  6. RENDER A SELECT LIST
  7. Almost same like render a TEXTFIELD, but avoid ['0']['value'] at the end
  8. <?php print drupal_render($form['group_company']['field_region']); ?>
  9. REMOVE AN INPUT FIELD
  10. You may want to disable an input form, usually you need to remove TITLE as shown below:
  11. <?php unset($form['title']); ?>
  12. HIDE AN INPUT FIELD (HIDE vs REMOVE!)
  13. You may still want to enable an input form but need to prevent it:
  14. <?php $form['title']['#access'] = FALSE; ?>
  15. SHOW ALL VARIABLES OF FORM
  16. You may want to know what variables available for you:
  17. <?php print_r($form); ?>
  18. REORDER
  19. Use ['#weight'] to reorder
  20. $form['buttons']['#weight'] = -50; // buttons at the top
  21. PRINT BUTTONS
  22. <?php print drupal_render($form['buttons']); ?>
  23. RENAMING BUTTON
  24. What is "Submit"? You may need to write it as "Save now!", don't you?
  25. $form['buttons']['submit']['#value'] = 'Save to Database';
  26. HIDE GROUP FIELD-SET
  27. $form['group_general']['#access'] = FALSE;
  28. HIDE BUTTON
  29. $form['buttons']['submit']['#access']= FALSE;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.