You are here

Form alter to node

Submitted by Peter on Fri, 2012-03-23 22:26

A Drupal add-on module to wrap a node around a form.

Drupal forms sometimes need code before or after the form. This module is an experiment on adding code before and after forms. You create a node of the following format. The code before the [form_alter_to_node] element is placed before the form element. The code after the [form_alter_to_node] element is placed after the form element.

This is text that goes before the form elements.
[form_alter_to_node]
This is text that goes after the form elements.

Currently the administration interface requires a manual specification of the form and node id.

Example forms

node_admin_content is the admin form listing content at /admin/content. system_site_maintenance_mode is the admin maintenance form. system_themes_admin_form is the admin form listing the themes and their status.

Form alter

The data supplied in the Drupal hook form_alter includes a list similar to the following list. hook_form_alter can be complex when the form is the slightest bit complicated. Adding something to the form in code via a module is difficult. This module simplifies the task a little bit by making the source of the data a node. You can then use regular node editing to modify the content.

a:18:{
  	 s:7:"#action";s:60:"/administrator/index.php?destination=administrator/index.php";
  	 s:3:"#id";s:15:"user-login-form";
  	 s:9:"#validate";a:3:{
  	   i:0;s:24:"user_login_name_validate";
  	   i:1;s:32:"user_login_authenticate_validate";
  	   i:2;s:25:"user_login_final_validate";
  	   }
  	 s:7:"#submit";a:1:{i:0;s:17:"user_login_submit";}
  	 s:4:"name";a:5:{s:5:"#type";s:9:"textfield";s:6:"#title";s:8:"Username";s:10:"#maxlength";i:60;s:5:"#size";i:15;s:9:"#required";b:1;}
  	 s:4:"pass";a:5:{s:5:"#type";s:8:"password";s:6:"#title";s:8:"Password";s:10:"#maxlength";i:60;s:5:"#size";i:15;s:9:"#required";b:1;}
  	 s:7:"actions";a:2:{s:5:"#type";s:7:"actions";s:6:"submit";a:2:{s:5:"#type";s:6:"submit";s:6:"#value";s:6:"Log in";}}
  	 s:5:"links";a:1:{s:7:"#markup";s:264:"<div class="item-list"><ul><li class="even first"><a href="/user/register" title="Create a new user account.">Create new account</a></li><li class="odd last"><a href="/user/password" title="Request new password via e-mail.">Request new password</a></li></ul></div>";}
  	 s:8:"#form_id";s:16:"user_login_block";
  	 s:5:"#type";s:4:"form";
  	 s:9:"#build_id";s:48:"form-j3bT94wiQBnu8wQcKgqYJH_YIQQNNa4Lxbku3Q8";
  	 s:13:"form_build_id";a:4:{
  	   s:5:"#type";s:6:"hidden";
  	   s:6:"#value";s:48:"form-j3bT94wiBmnu8wQcKgqYJH_YIQQNNa4Lxbku3Q8";
  	   s:3:"#id";s:48:"form-j3bT94wQBnu8wQcKgqYJzHYIQQjNNa4LLxbk3Q8";
  	   s:5:"#name";s:13:"form_build_id";
  	   }
  	 s:7:"form_id";a:3:{s:5:"#type";s:6:"hidden";s:6:"#value";s:16:"user_login_block";s:3:"#id";s:21:"edit-user-login-block";}
  	 s:7:"#method";s:4:"post";
  	 s:15:"#theme_wrappers";a:1:{i:0;s:4:"form";}
  	 s:5:"#tree";b:0;
  	 s:8:"#parents";a:0:{}
  	 s:6:"#theme";a:1:{i:0;s:16:"user_login_block";}
  	 }

Sponsorable to do list

The following items are up for sponsorship if someone needs them.

  • Form URL to be admin/form_alter_to_node/x to separate from regular URLs.
  • Content type to be Form alter to node. Not necessary but neat and clean.
  • Body to be description to allow for free form documentation.
  • Before section to be field named Before form.
  • After section to be field named After form.
  • The form id to node connection to be a formal table to allow for high volume requires.