Skip to content

generic_form

generic_form

This is a snippet.

<div class="form">
<form name="##$name##" id="##$name##" action="##$action##" method="post">
<p><small><span class="required">*</span> denotes a required field</small></p>
<table cellspacing="0" cellpadding="0"> 
<tbody>
<?php
$formContent = '';
foreach ($hiddenFields as $hiddenField) {
	echo "<input type=\"hidden\" name=\"$hiddenField[name]\"
id=\"$hiddenField[id]\" value=\"" . addslashes($hiddenField['value']) .
"\" />";
}
$count = 0;
foreach ($components as $component) {
	if ($component->getIsHeading()) continue;
	$formContent .= '<tr valign="top"><td class="leftcell'.$count.'"';
        if (strlen($component->getLabel()) > 50) $formContent .= " colspan=\"2\"";
        $formContent .= "><label>";

        strlen(trim($component->getLabel())) ? $formContent .= $component->getLabel() . ':' : $formContent .= '&nbsp;';
	if ($component->getRequired()) $formContent .= ' <span class="required">*</span>';

        $formContent .= "</label></td>";

        if (strlen($component->getLabel()) > 50){ 
            $formContent .= "</tr><tr valign=\"top\"><td>&nbsp;</td><td>";
            $elements = $component->getElements();
            $half=count($elements);
            $i=0;
            foreach($elements as $elmn){
                if ($i == $half) $formContent .="";
                if ($elmn['type'] == FormComponent::ELEMENT_TYPE_FORM){
                    $val = $elmn['value'];
                    $formContent .= $val->display();
                }
                else if ($i != $half) $formContent .="<br/>";
                $i += 1;
            }
        }
        else $formContent .= '<td id="right_cell'.$count.'" class="rightcell">' . $component->display();
	if ($component->getHasError()) {
		$errMessage = $component->getErrorMessage();
		$formContent .= "<br /><span class=\"required\">";
		if (is_array($errMessage)) $formContent .= "<li>" .
arrayToList($errMessage, '</li><li>') . "</li>";
		else $formContent .= "&nbsp; $errMessage";
		$formContent .= "</span>";
	}
	$formContent .= "</td></tr>";
$count++;
} // Ends foreach


echo $formContent;
?>
<tr>
<td class="bottomleft">&nbsp;</td>
<td class="bottomright">
<input type="submit" alt="submit" class="formbttn"  name="submit" value="Submit" />
</td>
</tr>

</tbody>
</table>
</form>
</div>

Sites using this template:

Comments: