Location: PHPKode > scripts > Vision.To Form Elements > vision-to-form-elements/form_elements_class.php
<?php

/*
<!-- 
****************************************************
*         Website: http://www.vision.to            *
*         Copyright © by WWW.VISION.TO             *
*              All Rights Reserved                 *
*               Author:Femi Hasani                 *
*            Contact: hide@address.com               *
*  This application is protected by international  * 
*                copyright laws.                   *
****************************************************
-->
*/
/*

		Class: 		Vision.To From [Vision.To Universal Form Creator]
		Version: 	V 0.1.1
		License: 	Commercial
		Author: 	Femi Hasani
		Website: 	www.vision.to & wowdev.com
		Created:	2003
		Language:	PHP

		Features:
		XHTML Compatible Output
		Inteligent Element Selector
*/
//==============================================================================================================
class Vision_To_Form 

{
//==============================================================================================================
		var	$__field_type; 
		var	$__label; 
		var	$__field_name; 
		var	$__default_field_value; 
		var	$__field_size; 
		var	$__field_maxlength; 
		var	$__rows; 
		var	$__columns; 
		var	$__options;
		var	$__checked; 
		var	$__selected; 
		var	$__required; 
		var	$__max_filesize; 
		var	$__repeat_filed; 
		var	$__element_only;
		var	$__element_css;

//==============================================================================================================

//FORM FUNCTIONS ...

//FORM START ...
function form_generate_start_form($form_action, $enc_type, $form_name, $form_title) {
        $form_element = "<form method=\"post\" action=\"$form_action\" enctype=\"$enc_type\" name=\"$form_name\">\n";

        $form_element .= "<fieldset><legend><h2>$form_title</h2></legend>\n";
        return $form_element;
        }
//FORM END ...
function form_generate_end_form() {
        $form_element = "</fieldset></form>\n";
        return $form_element;
        }

//FORM TEXT INPUT

//==============================================================================================================

function form_generate_textinput($__label, $__field_name, $__field_size, $__field_maxlength, $__default_field_value, $__required, $__element_only) {
if($__field_size==""){$__field_size=50;}
if($__element_only == 1)
{
        $form_element = "<input class=\"VisionToInput\"  type=\"text\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" value=\"$__default_field_value\" maxlength=\"$__field_maxlength\">";
}
else
{
        $form_element = "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<input class=\"VisionToInput\"  type=\"text\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" value=\"$__default_field_value\" maxlength=\"$__field_maxlength\">";
        $form_element .= "<br class=\"clear-br\" /></div>\n";
}
		return $form_element;
        }



//==============================================================================================================

//FORM Password INPUT
function form_generate_password($__label, $__field_name, $__field_size, $__field_maxlength, $__default_field_value, $__required, $__element_only) {
if($__field_size==""){$__field_size=30;}
if($__element_only == 1)
{
        $form_element = "<input class=\"VisionToInput\"  type=\"password\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" value=\"$__default_field_value\" maxlength=\"$__field_maxlength\">";
}
else
{
        $form_element = "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<span class=\"field_input\"><input class=\"VisionToInput\"  type=\"password\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" value=\"$__default_field_value\" maxlength=\"$__field_maxlength\">";
        $form_element .= "<br class=\"clear-br\" /></div>\n";
}
        return $form_element;
        }

//==============================================================================================================

//FORM FILE INPUT
function form_generate_file_input($__label, $__field_name, $__field_size, $__max_filesize, $__default_field_value, $__required, $number_of_files, $__element_only) {

if($__field_size==""){$__field_size=35;}
if($__max_filesize==""){$__max_filesize=8000000;}
if($number_of_files==""){$number_of_files=0;}

//accept=""
    $form_element = "<fieldset><legend>$__label $__required</legend>";
    $form_element .= "";
	for($i=0;$i<$number_of_files;$i++)
	{ 
	$form_element .= "<div class=\"form-element\"><div class=\"left-column\"><label for=\"".$__field_name."_".$i."\" title=\"$__label $i\">$__label $i $__required :</label></div><input class=\"VisionToInput\" type=\"file\" id=\"".$__field_name."_".$i."\" name=\"".$__field_name."[]\" size=\"$__field_size\"><br class=\"clear-br\" /></div>\n";
	}
	$form_element .= "</fieldset>";


        return $form_element;
        }

//==============================================================================================================

//FORM CHECK BOX INPUT
function form_generate_checkbox($__label, $__field_name, $__options, $__default_field_value, $__checked, $__required, $__element_only) {

if($__element_only == 1)
{
        $form_element = "<input class=\" VisionToInput\"  type=\"checkbox\" id=\"$__field_name\" name=\"$__field_name\" value=\"$__default_field_value\" $__checked>$__label $__required";
}
else
{
        $form_element = "<div class=\"VisionToFormElement\">";
        $form_element .= "<input class=\" VisionToInput\"  type=\"checkbox\" id=\"$__field_name\" name=\"$__field_name\" value=\"$__default_field_value\" $__checked><label for=\"$__field_name\">$__label $__required  </label>";
        $form_element .= "<br class=\"clear-br\" /></div>\n";
}
        return $form_element;
        }

//==============================================================================================================

//FORM RADIO BUTTON INPUT
function form_generate_radio($__label, $__field_name, $__options, $__default_field_value, $__selected, $__required, $__element_only) {

if($__element_only == 1)
{
        $form_element = "<input class=\" VisionToInput\"  type=\"radio\" id=\"$__field_name\" name=\"$__field_name\" value=\"$__default_field_value\" $__selected>$__label $__required ";
}
else
{
        $form_element = "<div class=\"VisionToFormElement\">";
        $form_element .= "<input class=\" VisionToInput\"  type=\"radio\" id=\"$__field_name\" name=\"$__field_name\" value=\"$__default_field_value\" $__selected><label  for=\"$__field_name\">$__label $__required  </label>";
        $form_element .= "<br class=\"clear-br\" /></div>\n";
}
        return $form_element;
        }

//==============================================================================================================

//FORM TEXT AREA
function form_generate_textarea($__label, $__field_name, $__default_field_value, $__rows, $__columns, $__required, $__element_only) {
if($__rows==""){$__rows=5;}
if($__columns==""){$__columns=50;}
if($__element_only == 1)
{
        $form_element = "<textarea class=\"VisionToTextarea\" id=\"$__field_name\" name=\"$__field_name\" rows=\"$__rows\" cols=\"$__columns\">".$__default_field_value."</textarea>\n";
}
else
{
        $form_element = "<fieldset><legend>$__label $__required</legend>";
        $form_element .= "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<textarea class=\"VisionToTextarea\" id=\"$__field_name\" name=\"$__field_name\" rows=\"$__rows\" cols=\"$__columns\">".$__default_field_value."</textarea><br class=\"clear-br\" /></div>\n";
        $form_element .= "</fieldset>\n";
}
        return $form_element;
        }


//===============================================================================================================



//==============================================================================================================

//FORM IMG
function form_generate_image($__label, $__field_name, $image, $width,  $height) {
       
	   $form_element = "<input type=\"image\" id=\"$__field_name\" name=\"$__field_name\" src=\"$image\" width=\"$width\" height=\"$height\" alt=\"$__label\" border=\"0\" />\n";
        return $form_element;
        }


//===============================================================================================================

//================================================= CHECK BOX LIST ==============================================

//FORM CHECKBOX
function form_generate_checkbox_list($__label, $__field_name, $__options, $__default_field_value, $__checked, $__required, $__element_only) {

        $form_element = "<fieldset><legend>$__label $__required</legend><div class=\"VisionToFormElement\">";
        $form_element .= "<div class=\"checkbox-list-container\">\n";
                $opts ="";
				$subarray="";
				$op_name="";
				$__default_field_values="";
                $opts = explode("|", $__options);
				$field_index=1;
		        $opts =array_unique($opts);
       while (list($op_name, $subarray) = each($opts)) 
	   {        

				list($__default_field_values, $op_name) = explode(";", $subarray);
				if($__default_field_values== $__default_field_value)
				{
				$form_element .= "<div class=\"checkboxlist\"><label for=\"".$__field_name."_".$field_index."\" title=\"$op_name\"><input class=\"VisionToCheckBoxInput\"  type=\"checkbox\" id=\"".$__field_name."_".$field_index."\" name=\"".$__field_name."[]\" value=\"$__default_field_values\" $__checked><span>$op_name</span></label></div>";
				}
				else
				{
 				$form_element .= "<div class=\"checkboxlist\"><label for=\"".$__field_name."_".$field_index."\" title=\"$op_name\"><input class=\"VisionToCheckBoxInput\"  type=\"checkbox\" id=\"".$__field_name."_".$field_index."\" name=\"".$__field_name."[]\" value=\"$__default_field_values\" ><span>$op_name</span></label></div>";				
				}
        $field_index++;
		}
		
        $form_element .= "</div></div></fieldset>\n";
        return $form_element;
        }

//===========================================================================================================
//============================================= RADIO LIST ==================================================
//FORM RADIO LIST
function form_generate_radio_list($__label, $__field_name, $__options, $__default_field_value, $__checked, $__required, $__element_only) {
        $form_element = "<fieldset><legend>$__label $__required</legend><div class=\"VisionToFormElement\">";
        $form_element .= "<div class=\"radio-list-container\">\n";
                $opts ="";
				$subarray="";
				$op_name="";
				$__default_field_values="";

                $opts = explode("|", $__options);
				$field_index=1;
		        $opts =array_unique($opts);
       while (list($op_name, $subarray) = each($opts)) 
	   {        

				list($__default_field_values, $op_name) = explode(";", $subarray);
				if($__default_field_values== $__default_field_value)
				{
				$form_element .= "<div class=\"radiolist\"><label for=\"".$__field_name."_".$field_index."\" title=\"$op_name\"><input class=\"VisionToRadioInput\"  type=\"radio\" id=\"".$__field_name."_".$field_index."\" name=\"".$__field_name."\" value=\"$__default_field_values\" $__checked ><span>$op_name</span></label></div>";
				}
				else
				{
 				$form_element .= "<div class=\"radiolist\"><label for=\"".$__field_name."_".$field_index."\" title=\"$op_name\"><input class=\"VisionToRadioInput\"  type=\"radio\" id=\"".$__field_name."_".$field_index."\" name=\"".$__field_name."\" value=\"$__default_field_values\" ><span>$op_name</span></label></div>";							
				}
                $field_index++;
		}
		
        $form_element .= "</div></div></fieldset>\n";
        return $form_element;
        }


//===========================================================================================================
//============================================ DROPDOWN LISTBOX MULTI ==================================================

//FORM SELECT LIST-BOX MULTI
function form_generate_select($__label, $__field_name, $__field_size, $__options, $__default_field_value, $__required, $__element_only) {
if($__field_size==""){$__field_size=1;}
$form_element = "";

if($__field_size > 1)
{

        $form_element .= "<fieldset><legend>$__label $__required</legend>";
        $form_element .= "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<select class=\"VisionToSelect\" id=\"$__field_name\" name=\"".$__field_name."[]\" size=\"$__field_size\" multiple>\n";
}
else
{

        $form_element .= "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<select class=\"VisionToSelect\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\">\n";
}

                $opts ="";
				$subarray="";
				$op_name="";
				$__default_field_values="";
                $opts = explode("|", $__options);
		        $opts =array_unique($opts);
       while (list($op_name, $subarray) = each($opts)) 
	   {        

				list($__default_field_values, $op_name) = explode(";", $subarray);
				if($__default_field_values== $__default_field_value)
				{
                $form_element .= "<option value=\"$__default_field_values\" selected >$op_name</option>\n";
				}
				else
				{
                $form_element .= "<option value=\"$__default_field_values\">$op_name</option>\n";				
				}
		}
		
        $form_element .= "</select></div>\n";
		if($__field_size > 1)
        {
        $form_element .= "</fieldset>\n";
        }
        return $form_element;
        }






//==============================================================================================================
//============================================ DROPDOWN LISTBOX SINGLE==================================================

//FORM SELECT LIST-BOX SINGLE
function form_generate_select_single($__label, $__field_name, $__field_size, $__options, $__default_field_value, $__required, $__element_only) {
if($__field_size==""){$__field_size=1;}
$form_element = "";
if($__element_only == 1)

{        
        //$form_element .= "<select class=\"VisionToSelect\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" onchange=\"update(this.options[this.selectedIndex].value)\" >\n";
       $form_element .= "<select class=\"VisionToSelect\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\" >\n";
                $opts ="";
				$subarray="";
				$op_name="";
				$__default_field_values="";
                $opts = explode("|", $__options);
		        $opts =array_unique($opts);
       while (list($op_name, $subarray) = each($opts)) 
	   {        

				list($__default_field_values, $op_name) = explode(";", $subarray);
				/*
				if(CCGetParam($__field_name,"")!="")
				{
				$form_element .= "<option value=\"".CCGetParam($__field_name,"")."\" selected >$op_name</option>\n";
				}
				*/
				if($__default_field_values== $__default_field_value)
				{
                $form_element .= "<option value=\"$__default_field_values\" selected >$op_name</option>\n";
				}
				else
				{
                $form_element .= "<option value=\"$__default_field_values\">$op_name</option>\n";				
				}
		}
		
        $form_element .= "</select>\n";
}
else
{


        $form_element .= "<div class=\"form-element\"><div class=\"left-column\"><label for=\"$__field_name\" title=\"$__label\">$__label $__required :</label></div>";
        $form_element .= "<select class=\"VisionToSelect\" id=\"$__field_name\" name=\"$__field_name\" size=\"$__field_size\">\n";


                $opts ="";
				$subarray="";
				$op_name="";
				$__default_field_values="";
                $opts = explode(";", $__options);
		        $opts =array_unique($opts);
       while (list($op_name, $subarray) = each($opts)) 
	   {        

				list($__default_field_values, $op_name) = explode(";", $subarray);
				if($__default_field_values== $__default_field_value)
				{
                $form_element .= "<option value=\"$__default_field_values\" selected >$op_name</option>\n";
				}
				else
				{
                $form_element .= "<option value=\"$__default_field_values\">$op_name</option>\n";				
				}
		}
		
        $form_element .= "</select></div>\n";
}
        return $form_element;
        }






//==============================================================================================================
//FORM HIDDEN INPUT
function form_generate_hidden($__field_name, $__default_field_value) {
        $form_element = "<input type=\"hidden\" name=\"name\" value=\"$__default_field_value\">\n";
        return $form_element;
        }

//==============================================================================================================

//FORM SUBMIT BUTTON
function form_generate_submit($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only) {
if($__element_only == 1)
{
        $form_element = "<input class=\"VisionToButton\"  type=\"submit\" name=\"$__field_name\" value=\"$__default_field_value\">";
}
else
{
        $form_element = "<div class=\"VisionToFormElement\"><span class=\"field_caption\">$__label $__required  </span>";
        $form_element .= "<span class=\"field_input\"><input class=\"VisionToButton\"  type=\"submit\" name=\"$__field_name\" value=\"$__default_field_value\"></span></div>\n";
        //$form_element .= "<br class=\"clear-br\" /></div>\n";
}
        return $form_element;
        }

//==============================================================================================================

//FORM RESET BUTTON
function form_generate_resetform($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only) {
        $form_element = "<div class=\"VisionToFormElement\"><span class=\"field_caption\">$__label $__required  </span>";
        $form_element .= "<span class=\"field_input\"><input class=\"VisionToButton\"  type=\"reset\" name=\"$__field_name\" value=\"$__default_field_value\"></span></div>\n";
        return $form_element;
        }

//==============================================================================================================

//FORM RESET BUTTON

function form_generate_back_button($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only) {
        $form_element = "<div class=\"VisionToFormElement\"><span class=\"field_caption\">$__label $__required  </span>";
        $form_element .= "<span class=\"field_input\"><input class=\"VisionToButton\"  type=\"reset\" value=\"$__default_field_value\"></span></div>\n";
        return $form_element;
        }

//==============================================================================================================

/* ELEMENT SELECTOR */
function add_form_element
(
$__field_type, 
$__label, 
$__field_name, 
$__default_field_value, 
$__field_size, 
$__field_maxlength, 
$__rows, $__columns, 
$__options, 
$__checked, 
$__selected, 
$__required, 
$__max_filesize, 
$__repeat_filed, 
$__element_only
)

{
//$VisionToForm = new Vision_To_Form;
$number_of_files=$__repeat_filed;
if(!$__field_maxlength){$__field_maxlength=255;}
if(!$__checked){$__checked="checked";}
if($__max_filesize==""){$__max_filesize=8000000;}
if($__element_only==""){$__element_only=0;}

/* ELEMENT SELECTOR */
switch($__field_type)
{

  //TEXT
  case "text":return $this->form_generate_textinput($__label, $__field_name, $__field_size, $__field_maxlength, $__default_field_value, $__required, $__element_only); 
  
  break;
  //HIDDEN
  case "hidden": return $this->form_generate_hidden($__field_name, $__default_field_value, $__required, $__element_only); 
  
  break;

  //FILE INPUT
  case "file": return $this->form_generate_file_input($__label, $__field_name, $__field_size, $__max_filesize, $__default_field_value, $__required, $number_of_files, $__element_only); 
  
  break;

  //LISTBOX
  case "select": return $this->form_generate_select_single($__label, $__field_name, $__field_size, $__options, $__default_field_value, $__required, $__element_only); 
  
  break;
  //CHECKBOX
  case "checkbox": return $this->form_generate_checkbox_list($__label, $__field_name, $__options, $__default_field_value, $__checked, $__required, $__element_only); 
  
  break;
  //RADIO
  case "radio": return $this->form_generate_radio_list($__label, $__field_name, $__options, $__default_field_value, $__checked, $__required, $__element_only); 
  
  break;
  //TEXTAREA
  case "textarea": return $this->form_generate_textarea($__label, $__field_name, $__default_field_value, $__rows, $__columns, $__required, $__element_only); 
  
  break;
  //PASSWORD
  case "password": return $this->form_generate_password($__label, $__field_name, $__field_size, $__field_maxlength, $__default_field_value, $__required, $__element_only); 
  break;
  //SUBMIT
  case "submit": return $this->form_generate_submit($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only); 
  break;
  //RESET
  case "reset": return $this->form_generate_resetform($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only); 
  break;
  //BACK
  case "back": return $this->form_generate_back_button($__label, $__field_name, $__field_size, $__default_field_value, $__required, $__element_only);
  break;
  //DEFAULT
  default: return $this->form_generate_textinput($__label, $__field_name, $__field_size, $__field_maxlength, $__default_field_value, $__required, $__element_only);
}

}
//==============================================================================================================
} //End of Vision_To_Form CLASS
//==============================================================================================================
?>
Return current item: Vision.To Form Elements