All pastes #476548 Raw Edit

Syosoft

public php v1 · immutable
·published 2007-05-08 04:51 UTC
rendered paste body
<?php	class page { 		private $form_data = array(); // Holds the vars		private $output = ''; // Provided by a buffer of some sort		/*			Functions to grab the template(s) and content and setup $this->output. It would then call			$this->write_form_variables() to auto populate any found forms.		*/		private function set_form_field_value($form,$field,$value) { 			$this->form_data[$form] = !isset($this->form_data[$form]) ? array() : $this->form_data[$form];			$this->form_data[$form][$field] = $value;		}		private function write_form_variables() {			if(sizeof($this->form_data) == 0 || !preg_match_all('/<form.*?<\/form>/is',$this->output,$forms)) : 				return false;			endif;					foreach($forms[0] as $form) : 				$new_form = $form;				eregi('name="([a-zA-Z0-9]+)"',$form,$name);				$form_data = !isset($this->form_data[$name[1]]) ? array() : $this->form_data[$name[1]];						preg_match_all('/<(input|textarea|select).*?name="(.*?)".*?>/',$form,$fields);						for($i=0;$i<sizeof($fields[0]);++$i) : 					$field_def		= $fields[0][$i];					$field_class	= $fields[1][$i];					$field_name		= $fields[2][$i];							if(!isset($form_data[$field_name])) : 						continue;					else : 						$field_value = $form_data[$field_name];					endif;							switch($field_class) : 						case 'input':							preg_match('/type="(.*?)"/i',$fields[0][$i],$type);							$field_type = $type[1];									switch($field_type) :								default : 								case 'text' : 								case 'password' : 								case 'hidden' : 									$new_field_def	= str_replace(array(' value=""','>'),array('',' value="'.$field_value.'">'),$field_def);									$new_form		= str_replace($field_def,$new_field_def,$new_form);								break;								case 'checkbox' :								case 'radio' : 									$new_field_def	= str_replace(array(' checked="checked','value="'.$field_value.'"'),array('','value="'.$field_value.'" checked="checked"'),$field_def);									$new_form		= str_replace($field_def,$new_field_def,$new_form);								break;							endswitch;						break;						case 'textarea':							$new_form = str_replace($field_def.'</textarea>',$field_def.$field_value.'</textarea>',$new_form);						break;						case 'select' :							if(!preg_match('/'.$field_def.'(.*?)<\/select>/is',$new_form,$field_def)) : 								continue;							endif;									$field_def		= $field_def[0];							$new_field_def	= str_replace(array(' selected="selected"','value="'.$field_value.'"'),array('','value="'.$field_value.'" selected="selected"'),$field_def);							$new_form		= str_replace($field_def,$new_field_def,$new_form);						break;					endswitch;				endfor;						$this->output = str_replace($form,$new_form,$this->output);			endforeach;		}	}?>