Tag Archive for forms

Assign POST/GET to internal array

<?php
// Loop through the fields in the POST and assign them to our internal variable.
// There are several special cases we need to handle differently, so we'll skip
// them for now.
foreach($_POST as $key=>$value) {
switch($key) {
case 'submit'; // Completely skip over the submit button
case "field_1";
case "/^a regex$/";
case "field_20";
default:
$myArray[$key] = $value;
}
}
?>

source

submitEvents – Javascript form submission handler

//
// submitEvent 0.2
// 19/08/2008
//
// Version History:
//
// 0.2
//   Slightly better fix, using .bind(this) instead of a temporary
// window.submitFormData var
//
// 0.11
//   Hacky fix for IE6
//
// 0.1
//   Initial release
//
//
// A small class for easily implementing many submit events including
// displaying a confirmation dialog, disabling the submit button and
// displaying an informative div so that the users stay informed.
//
// Please see example.html for some examples
//
// All the options are detailed below, and the defaults can be easily
// changed to suit your needs.
//
// Requires mootools 1.2 (I don't think it'll work with lower) although
// I may also make a prototype/scriptaculous version if required.
//
// This software is released under the Creative Commons Share Alike
// license.
//
// Dom
//
// <a href="http://www.dom111.co.uk/" >http://www.dom111.co.uk/</a>
//
var submitEvent = new Class({
Implements: [Options],

// options
//
// the default options
// these can be overridden here if you use the same
// settings often, to save yourself time
//
options: {
// confirmation
//
//  enabled: boolean
//  text: text to display on said dialog box
//  confirmed: used internally to make sure the
// confirmation isn't displayed again if there's a
// timeout
confirmation: {
enabled: false,
text: 'Are you sure?',
confirmed: false
},
// submitButton
//
//  object: the object (or id as string) that is the
// primary submit button for f
//  changeText: whether or not to change the button's
// text on submit
//  newText: text to change the button to
//
submitButton: {
object: null,
disable: true,
changeText: true,
text: 'Please wait...'
},
// informationDiv
//
//  display: whether or not to diplay an information
// div
//  className: CSS class to apply to the div
//  centered: whether to horizontally center the div
// (uses left: xxpx so class must add position absolute)
//  text: text (or HTML to populate the div with
//  inject: element to inject the div into (this.form
// is used if this is left as null/false)
//  injectTo: position to inject element to eg. bottom,
// top, before, after defaults to after
//
informationDiv: {
enabled: true,
className: '',
centered: true,
text: 'Loading...',
inject: null,
injectTo: 'after'
},
//
// undo
//  enabled: boolean
//  timeout: in seconds to run specified undo tasks
//
// submitButton:
//  enabled: re-enable the submit button
//  newText: text to display on the newly enabled
// submit button
//
// informationDiv
//  text: updated text to display
//  className: updated CSS class to apply
undo: {
enabled: true,
timeOut: 30,
submitButton: {
enabled: true,
newText: 'Try Again'
},
informationDiv: {
enabled: true,
text: 'Sorry, there was a problem.',
className: ''
}
},
//
// ajax
//
// makes the form submission use ajax
//
//  enabled: boolean
//  update: the dom node, or a string id of the element
// to update, if not set, defaults to this.form
//  appendUrl: a query string to append to the ajax request
// (could be used to surpress header/footer or just distinguish
// between ajax/normal requests)
//
ajax: {
enabled: false,
udpate: null,
appendUrl: 'ajax=1'
}
},

initialize: function(f, o) {
// if f is a string, look for that element id...
if ($type(f) == 'string') {
f = $(f);
}

// if f still isn't an object, give up...
if ($type(f) != 'object' && $type(f) != 'element') {
return true;  // ... and submit the form, because we can't do anything...
}

// store the form object as this.form
this.form = f;

// save the old onsubmit function
this.preservedOnSubmit = this.form.onsubmit || function() {};

// merge the options...
this.setOptions(o || {});
if (!(this.options.submitButton.object)) {
this.options.submitButton.object = this.findSubmitButton(this.form);
if (!(this.options.submitButton.object.id)) {
this.options.submitButton.object.id = 'submitEventSubmitButton_' + new Date().getTime();
}
}

this.options.submitButton.oldText = this.options.submitButton.object.value;

this.informationDiv = false;
this.submitButtonFunctionTimeout = false;
this.informationDivFunctionTimeout = false;
},

// process
//
// do the magic!
process: function() {
// carry out functions in order:
//
// check for a confirmation message first, as if the user
// wants to cancel we could save ourselves some time
if ((this.options.confirmation.enabled) && !(this.options.confirmation.confirmed)) {
// if the text is blank or it's not a string
if (!(this.options.confirmation.text) || $type(this.options.confirmation.text) != 'string') {
// set it to some default text
this.options.confirmation.text = 'Are you sure?'
}
// set c to true/false from the user box
var c = confirm(this.options.confirmation.text);

// if it's true
if (c) {
// set the confirmed variable to true so the dialog isn't displayed again
this.options.confirmation.confirmed = true;
} else {
// else stop processing anything
return false;
}
}

// next, change the submit button if required
if ((this.options.submitButton.changeText) || (this.options.submitButton.disable)) {
// if the object, isn't an object, make it one
if ($type(this.options.submitButton.object) == 'string') {
this.options.submitButton.object = $(this.options.submitButton.object);
}

// create a variable for the button, of the object
var button = this.options.submitButton.object;

// make sure it's not null or false
if (button) {

// if we're supposed to change the text, do...
if (this.options.submitButton.changeText) {
button.value = this.options.submitButton.text || 'Please wait...';
}

// if we're supposed to disable it, do!
if (this.options.submitButton.disable) {
button.disabled = true;
}
}
}

// information div... display if required
if ((this.informationDiv) || (this.options.informationDiv.enabled)) {
if ((this.options.informationDiv.text) && $type(this.options.informationDiv.text) == 'string') {
// check the text is a string and nothing else
if (!this.informationDiv) {
// create a div element
this.informationDiv = new Element('div', {
'id': 'submitEventInformationDiv_' + new Date().getTime()
});

} else {
if (this.options.undo.informationDiv.className) {
this.informationDiv.removeClass(this.options.undo.informationDiv.className);
}
}

// set the innerHTML to the specified 'text', or default
this.informationDiv.set('html', this.options.informationDiv.text || 'Loading...');
// add the className if set
this.informationDiv.addClass(this.options.informationDiv.className || '')
// inject the element into the specified element, or this.form if not specified
this.informationDiv.inject(this.options.informationDiv.inject || this.form, this.options.informationDiv.injectTo || 'after');

if (this.options.informationDiv.centered) {
this.informationDiv.setStyle('left', this.getCenter(this.informationDiv) + 'px');
}
}
}

// undo, the best bit...
//
// if we can run undo tasks and at least one is enabled...
if (this.options.undo.enabled && (this.options.undo.submitButton.enabled || this.options.undo.informationDiv.enabled)) {
// set the timeout variable to seconds * 1000 (milliseconds)
var timeOut = (this.options.undo.timeOut || 30) * 1000;

// if we can run the undo on the button
if (this.options.undo.submitButton.enabled) {
// build the function to re-enable it and change the text
submitButtonFunction = function() {
var button = this.options.submitButton.object;
button.disabled = false;
button.value = this.options.undo.submitButton.newText || this.options.submitButton.oldText;
}
// use mootools timeout function, which allows this to be used
this.submitButtonFunctionTimeout = submitButtonFunction.delay(timeOut, this);
}

// if we can do the same magic with the information div...
if (this.options.undo.informationDiv.enabled) {

// build a function to change the text
informationDivFunction = function() {
if (this.options.undo.informationDiv.text) {
this.informationDiv.set('html', this.options.undo.informationDiv.text || 'Sorry, there was a problem.');
}

// and add the new class
if (this.options.undo.informationDiv.className) {
this.informationDiv.removeClass(this.options.informationDiv.className || '');
this.informationDiv.addClass(this.options.undo.informationDiv.className);
}

if (this.options.informationDiv.centered) {
this.informationDiv.set('styles', {
'left': this.getCenter(this.informationDiv) + 'px'
})
}
}

// another lovely timeout function
this.informationDivFunctionTimeout = informationDivFunction.delay(timeOut, this);
}
}

// if we're ajaxing it up...
if (this.options.ajax.enabled) {
// create a mootools request object
this.ajaxRequest = new Request.HTML({
// populate it with all the details from the HTML form
method: this.form.method,
url: this.appendQueryString(this.form.action),
// data: this.form.toQueryString(), // fails in IE 6?
data: this.formToQueryString(this.form),
update: this.options.ajax.update || this.form,
// add an oncomplete function to remove the additions
onComplete: function() {
$clear(this.submitButtonFunctionTimeout);
$clear(this.informationDivFunctionTimeout);
if ($(this.informationDiv.id)) {
$(this.informationDiv.id).destroy();
}
if ($(this.options.submitButton.object.id)) {
$(this.options.submitButton.object.id).value = this.options.submitButton.oldText;
$(this.options.submitButton.object.id).disabled = false;
}
}.bind(this)
}).send();

// make sure the main form isn't submitted
return false;
} else {
return true;  // post the form
}
},

// findSubmitButton
//
// returns the first submit button on a form
//
findSubmitButton: function(f) {
// if f fails use document
f = f || document;
// loop through all input elements in f
var i = f.getElementsByTagName('input');
for (var x = i.length - 1; x >= 0; x--) {
if (i[x].type == 'submit' || i[x].type == 'image') {
return i[x];
}
}
// loop through all button elements in f
var i = f.getElementsByTagName('button');
for (var x = i.length - 1; x >= 0; x--) {
if (i[x].type == 'submit') {
return i[x];
}
}
// we didn't find anything, so return null
return null;
},

// getCenter
//
// returns the width of the screen / 2 or the width
// of the screen - el.width / 2 for centering elements
//
getCenter: function(el) {
// w contains w.x and w.y
var w = window.getSize();

// if el is a string, make it an element
if ($type(el) == 'string') {
el = $(el);
}

// if el is all working
if (el) {
// get the sizes of it
var e = el.getSize();

// return the screen size minus the elements width / 2
return (w.x - e.x) / 2;

} else {
// just return the screen size / 2
return w.x / 2;
}
},

// appendQueryString
//
// returns the url with the extra query string correctly
// appended
//
appendQueryString: function(u) {
if (q = this.options.ajax.appendUrl) {
return (u.match(/?/)) ? u + '&' + q : u + '?' + q;
} else {
return u;
}
},

// formToQueryString
//
// Ripped and modified from mooTools as form.toObject() was failing.
//
formToQueryString: function(form) {
var obj = {};

var inputs = form.getElementsByTagName('input');
var selects = form.getElementsByTagName('select');
var textareas = form.getElementsByTagName('textarea');

var els = [];
els[els.length] = inputs;
els[els.length] = selects;
els[els.length] = textareas;

for (var i = 0; i < els.length; i++) {
for (var j = 0; j < els[i].length; j++) {
var name = els[i][j].name;
var value = els[i][j].value;
if ((value !== false) && name) obj[name] = value;
}
}

var s = '';

$each(obj, function(value, name) {
s += name + '=' + value + '&';
});

return s;
}

});

Examples:

<?php
if (!empty($_POST)) {
sleep(5);
var_dump($_POST);
die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>submitEvents</title>

<script src="/js/mootools1.2.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/submitEvent.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form action="examples.php" method="post" onsubmit="return new submitEvent(this).process();">
<p>This form is using the default options</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { ajax: { enabled: true, update: $('test1') }, undo: { timeOut: 3 } } ).process();">
<p>This form is using the default options with ajax (and a very low undo wait, to test the return to normality...)</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>
<div id="test1"></div>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { confirmation: { enabled: true, text: 'Sure you're ready to submit?' } } ).process();">
<p>This form is using the default options with a confirmation dialog</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" onsubmit="return new submitEvent(this, { confirmation: { enabled: false }, ajax: { enabled: false }, informationDiv: { enabled: false } } ).process();">
<p>This form is only going to disable the submit button</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<form action="examples.php" method="post" id="totallyJavascriptForm">
<p>This form is using the default options, but specified directly, and the event is added via javascript</p>
<p><input type="text" name="name" value="" id="name"/></p>
<p><input type="text" name="email" value="" id="email"/></p>
<p><input type="submit" name="submitButton" value="Submit"/></p>
</form>

<script type="text/javascript" charset="utf-8">
$('totallyJavascriptForm').addEvent('submit', function() {
return new submitEvent(this, {
confirmation: {
confirmation: {
enabled: false,
text: 'Are you sure?',
confirmed: false
},
submitButton: {
object: null,
disable: true,
changeText: true,
text: 'Please wait...'
},
informationDiv: {
enabled: true,
className: '',
centered: true,
text: 'Loading...',
inject: null,
injectTo: 'after'
},
undo: {
enabled: true,
timeOut: 30,
submitButton: {
enabled: true,
newText: 'Try Again'
},
informationDiv: {
enabled: true,
text: 'Sorry, there was a problem.',
className: ''
}
},
ajax: {
enabled: false,
udpate: null,
appendUrl: 'ajax=1'
}
}
}).process()
});
</script>

</body>
</html>

source

jQuery Dynamic Form Field Addition

<script type="text/javascript" charset="utf-8">
$(function() {
var fieldCount = 1;
$("#addFieldButton").click(function() {
fieldCount++;
if(fieldCount <= 5)
{
var fieldID = "recipient_email_" + fieldCount;
$("#additionalEmails").append("<label for='"+fieldID+"'>Recipient Email "+fieldCount+": </label>"+
"<input type='text' name='"+fieldID+"' " +
"id='"+fieldID+"' size='30'><br />" );
}
else
{
alert("Maximum email fields reached.");
}
});
});
</script>

source

form input prefill clearer and reset

// form input prefill clear on focus, and reset on blur (if empty)

function prefillClear(field) {

if (field.defaultValue==field.value) {field.value = '';}

else if (field.value == '') {field.value = field.defaultValue;}

}

// usage

<input type="text" name="input1" value="Enter your data" onfocus="prefillClear(this);" onblur="prefillClear(this);" />

// suggest using some further javascript to parse all input fields and apply these functions on domReady. This would save having to put the function calls inline.

source

Don’t show the blue effect of forms in safari

input, textarea  {
outline:none;
}

source

Write Text in a TextArea

<head>
<script language="javascript" type="text/javascript">
function addtext(text) {document.form.textarea.value = document.form.textarea.value+= text;}
</script>
</head>

<body>
<form action="" method="" name="form">
<textarea name="textarea" rows="" cols="" wrap="wrap"></textarea>
</form>
<a href="javascript:addtext('Text to add');">Add text</a>
</body>

source

Default text in a textbox

<input type="text" value="Site search" onfocus="if (this.value=='Site search') {this.value = '';}" onblur="if(this.value=='') {this.value = 'Site search';}" name="search" />

source

Functions package to SpeedUp web-forms creating process. V.0.2Beta

<?php
class forms implements iforms{

var $_inited=false;
var $_form=array();
var $_elems=array();
/**_elems: array(
array('id'=>'','name'=>'login','value'=>'','validate'=>true,'params'=>'','on'=>array('click'=>'event'))
);**/
/**
_fields: array('id'=>'','label'=>"Enter your login:","value"=>"el:21551","type"=>"pair","style"=>"");
**/
var $_fields=array();
var $_patterns=array();
var $_css=array();
var $_js=array();
var $_data='';

/**
* Constructor. Make new instance of the form container.
* @return
* @param $method Object
* @param $action Object
* @param $encoding Object
* @param $params Object[optional]
*/

public function init($method,$action,$encoding='',$name='',$id='',$params=array())
{
$id=($id)?'f_'.md5($time.$name.$action).'_'.mt_rand(10,99):'';
if($this->correctMethod($method) && !$this->_inited){
$this->_data='';
$this->_form['method']=$method;
$this->_form['action']=$action;
$this->_form['encoding']=$encoding;
$this->_form['params']=$params;
$this->_form['id']=$id;
$this->_form['name']=$name;
$this->initOthers();
$this->initPatterns();
$this->_inited=true;
}else{
return IFORM_WRONG_METHOD;
}
}

protected function initOthers(){
//CSS
$this->css['pairFieldLabelClass']='label';
$this->css['singleFieldLabelClass']='label label1 center';
$this->css['sinleFieldLabelStyle']='width:100%;clear:both;';
$this->css['formLegendClass']='legend';
$this->css['pairFieldValueClass']='value value1';
$this->css['pairFieldLabelClass']='label';
$this->css['rowClass']='row';
$this->css['formMainClass']='form';
$this->css['submit']='submit center';

//JS
$this->js['validateFunct']='Invis.tools.checkValue(this.id);';
}

public function addLegend($text){
$this->_form['legend']=sprintf($this->_patterns['formLegend'],$text);
}
protected function correctMethod($method)
{
switch($method){
case 'GET':
case 'POST':
case 'PUT':
return true;
}
return false;
}

/**
* Append eventHandler to added to form input element
* @return integer
* @param $name String
* @param $event String
* @param $handler String
*/
public function addEventHandler($name,$event,$handler){
if(trim($name)!='' && trim($event)!='' && trim($handler)!=''){
for($i=0;$i<count($this->_elems);$i++){
if($this->_elems['name']==$name){
$this->_elems[$i]['on'][]=array($event=>$handler);
break;
}
}
}else{
return IFORM_WRONG_PARAMS;
}
return 1;
}

/**
* Add submit control to the form
* @return void
* @param $name Object
* @param $value Object
* @param $style Object[optional]
*/
public function addSubmit($name,$value,$params=array())
{
if(trim($name)!=''){
$this->_submit=sprintf($this->_patterns['submit'],$name,$value,$this->_prepareParams($params));
}else{
return IFROM_WRONG_PARAMS;
}
}

/**
* Check that element with value of type $type equals $value
* @return integer
* @param $type String
* @param $value String
*/
protected function elemExists($type,$value)
{
for($i=0;$i<count($this->_elems);$i++){
switch($type)
{
case 'name':
if($this->_elems[$i]['name']==$value)return 1;
break;
case 'id':
if($this->_elems[$i]['id']==$value)return 1;
break;
}
}
return 0;
}

/**
* Set "important" parameter to the $id - input element
* @return integer
* @param $name String
*/
public function validateElement($id)
{
if(trim($name)==''){
return IFORM_WRONG_PARAMS;
}else{
if(!$this->elemExists("id",$id)){
return IFORM_WRONG_ELEM;
}else{
//FIX ERROR
$this->_elems[array_search($name,$this->_elems)]['validate']=true;
}
}
return 1;
}

/**
* Add input element to the current form
* @return String
* @param $type String
* @param $name String
* @param $parent String
* @param $id String[optional]
* @param $value String[optional]
* @param $validate Boolean[optional]
* @param $params String[optional]
*/
public function addInput($type,$name,$parent,$id='',$value='',$validate=false,$params='')
{
if(trim($type)!='' && trim($name)!='' && trim($parent)!=''){
$id=(!$id)?'i'.md5($name).'_'.count($this->_elems):$id;
$this->_elems[]=array(
'id'=>$id,
'type'=>$type,
'parent'=>$parent,
'name'=>$name,
'value'=>$value,
'validate'=>$validate,
'on'=>array(),
'params'=>$params
);
}else{
return IFROM_WRONG_PARAMS;
}
return $id;
}

/**
* Add field to the form
* @return String
* @param $label String
* @param $type String[optional]
* @param $el String[optional]
* @param $id String[optional]
* @param $params String[optional]
*/
public function addField($label,$type="pair",$value="",$id='',$params="")
{
$id=(!$id)?'f'.md5($label).'_'.count($this->_fields):$id;
$this->_fields[]=array("id"=>$id,"label"=>$label,"type"=>$type,"value"=>$value,"type"=>$type,"style"=>$params);
return $id;
}

/**
* Initialize system patterns
* @return void
*/
protected function initPatterns()
{
$this->_patterns['form']='<form action="%s" method="%s" encoding="%s" %s>';
$this->_patterns['inputI']='<input type="%s" name="%s" id="%s" %s %s %s/>';
$this->_patterns['inputD']='<%s name="%s" id="%s" %s %s %s>%s</%s>';
$this->_patterns['fieldsingle']='<div class="%s" style="width:100%;clear:both;" id="%s" %s%s</div>';
$this->_patterns['fieldpair']='<div class="%s" %s id="%s"><span class="%s" style="%s">%s</span><span style="%s">%s</span></div>';
$this->_patterns['formLegend']='<div class="'.$this->css['formLegendClass'].'">%s</div>';
$this->_patterns['mainContainer']='<div class="'.$this->css['formMainClass'].'">';
$this->_patterns['endContainer']='</div></form>';
$this->_patterns['submit']='<div class="row"><span class=" '.$this->css['submitClass'].'" style="clear:both;"><input type="submit" name="%s" value="%s" %s/></span></div>';
}

/**
* Get inputs which referers to $parent-field
* @return String
* @param $parent Object
*/
protected function _getChildsInputs($parent)
{
$res='';
for($i=0;$i<count($this->_elems);$i++)
{
if($this->_elems[$i]['parent']==$parent){
switch($this->_elems[$i]['type']){
case 'password':
case 'checkbox':
case 'text':
$res.=sprintf(
$this->_patterns['inputI'],
$this->_elems[$i]['type'],
$this->_elems[$i]['name'],
$this->_elems[$i]['id'],
($this->_elems[$i]['validate'])?'onclick="'.$this->js['validateFunct'].'"':'',
$this->_getEvents($i),
$this->_prepareParams($this->_elems[$i]['params'])
);
break;
case 'select':
$res.=sprintf(
$this->_patterns['inputI'],
$this->_elems[$i]['type'],
$this->_elems[$i]['name'],
$this->_elems[$i]['id'],
($this->_elems[$i]['validate'])?'onclick="'.$this->js['validateFunct'].'"':'',
$this->_getEvents($i),
$this->_prepareParams($this->_elems[$i]['params'])
);
break;
default:
$res=IFORM_WRONG_TYPE;
}
}
}
return $res;
}

/**
*
* @return String
* @param $elId Integer
*/
protected function _getEvents($elId){
$result=null;
if(array_search($elId,$this->_elems)!=-1){
foreach($this->_elems[$elId]['on'] as $k=>$v)
{
$result.=' on'.$k.'="return '.$v.'();" ';
}
}else{
$result=IFORM_NOT_EXISTS;
}
return $result;
}

private function _prepareParams($data)
{
$res=null;
if(is_array($data)){
foreach($data as $k=>$v)
{
$res.=$k."="".$data.""";
}
}
return $res;
}

/**
*
* @return String
*/
public function render($output=true)
{//<form action="%s" method="%s" encoding="%s" style="%s" %s>
#print_rbr($this->_elems);
#die_br($this->_fields);
$this->_data=sprintf($this->_patterns['form'],$this->_form['action'],$this->_form['method'],$this->_form['encoding'],$this->_prepareParams($this->_form['params']));
$this->_data.=sprintf($this->_patterns['mainContainer']);
$this->_data.=($this->_form['legend'])?$this->_form['legend']:'';
#die($this->_data);
$this->_data.='<input type="hidden" name="genericDATA" id="fX'.md5(time()).'" value="'.time().'"/>';
for($i=0;$i<count($this->_fields);$i++)
{#die_r($this->_fields[$i]);
switch($this->_fields[$i]['type'])
{

case 'pair':
//<div class="%s" id="%s"><span class="%s" style="%s">%s</span><span style="%s">%s(value)</span></div>'
$this->_data.=sprintf(
$this->_patterns['fieldpair'],
$this->css['rowClass'],
$this->_fields[$i]['params'],
$this->_fields[$i]['id'],
$this->css['pairFieldLabelClass'],
$this->css['pairFieldLabelStyle'],
$this->_fields[$i]['label'],
$this->css['pairFieldValueClass'],
($this->_fields[$i]['value']=='')?$this->_getChildsInputs($this->_fields[$i]['id']):$this->_fields[$i]['value']
);

break;
case 'single':
break;
}
}
$this->_data.=$this->_submit;
$this->_data.=sprintf($this->_patterns['endContainer']);
return ($output)?$this->_data:'';
}

function getData()
{
return $this->_data;
}

}
?>

source

Getting rid of form elements in a drupal theme function

function themename_type_node_form($form) {
if (isset($form['signup']['node_settings'])) {
$form['signup']['#collapsible'] = FALSE;
$form['signup']['#collapsed'] = FALSE;
unset($form['signup']['node_settings']['settings']['signup_forwarding_email']);
unset($form['signup']['node_settings']['settings']['signup_send_confirmation']);
unset($form['signup']['node_settings']['settings']['signup_confirmation_email']);
unset($form['signup']['node_settings']['settings']['signup_reminder']);
unset($form['signup']['node_settings']['settings']['signup_reminder_email']);
}
if (isset($form['locations'][0])) {
$form['locations'][0]['latitude']['#type'] = 'hidden';
$form['locations'][0]['latitude']['#value'] = '';
$form['locations'][0]['latitude']['#default_value'] = '';
$form['locations'][0]['longitude']['#type'] = 'hidden';
$form['locations'][0]['longitude']['#value'] = '';
$form['locations'][0]['longitude']['#default_value'] = '';

unset($form['locations'][0]['map']);
unset($form['locations'][0]['province']['#options']['xx']);
$form['locations'][0]['province']['#options']['xx'] = 'OTHER';
$form['locations'][0]['province']['#options']['us000'] = ' -- PLEASE CHOOSE ONE -- ';
}
unset($form['preview']);
return drupal_render($form);
}

source

CSS tableless forms using labels and spans

label {
display: block;
width: 125px;
float: left;
padding: 5px;
margin: 2px;
clear: both;
text-align: left;
}

span {
display: block;
margin: 3px;
}

span * {
margin: 0;
}

source