<commit_before><?php
#CreatedBy;Aaron;11OCT2014;Odin-Framework
 class bolt_form
{
	var $num_instances	= 0;

	#This is an HTML form that allows you to update/edit database data.
	function create($fields=NULL,$opts=NULL)
	{
		global $odin;
		$this->num_instances++;
		$instance	= (isset($o["instance"])?$o["instance"]:"inst-".$this->num_instances);
		$o			= array(
			"set_element"		=> "fieldset",
			"set_class"			=> "",
			"wrap_element"		=> "ul",
			"item_element"		=> "li",
			"legends"			=> array(),
			"new_set_on"		=> array(),
			"submit_text"		=> "Submit",
			"instance"			=> $instance,
			"field_types"		=> array(),
			"field_opts"		=> array(),
			"form_attrs"		=> array(
				"id"				=> $instance,
				"method"			=> "post",
				"action"			=> $_SERVER["REQUEST_URI"],
			),
		);
		if($opts)
			{ $o	= $odin->array->ow_merge_r($o,$opts); }
		#if fields were not passed, return false
		if(!$fields)
			{ return FALSE; }

		#create the dom object & elements
		$dom		= new DOMDocument();
		$form		= $dom->createElement("form");
		if(!empty($o["form_attrs"]))
		{
			foreach($o["form_attrs"] as $attr=>$value)
			{
				$form_attr			= $dom->createAttribute($attr);
				$form_attr->value	= $value;
				$form->appendChild($form_attr);
			}
		}
		#setup the elements (field)set & wrapper
		$set				= $dom->createElement($o["set_element"]);
		$set_attr			= $dom->createAttribute("class");
		$set_count			= 1;
		$set_attr->value	= "elements set-".$set_count.(!empty($o["set_class"])?" $o[set_class]":FALSE);
		$set->appendChild($set_attr);
		if($o["legends"])
		{
			$legend			= $dom->createElement("legend",is_array($o["legends"])?array_shift($o["legends"]):$o["legends"]);
			$set->appendChild($legend);
		}
		
		$wrapper			= $dom->createElement($o["wrap_element"]);
		$set->appendChild($wrapper);


		#append the submit button into this form, nested inside of its own div.buttons wrapper.
		$submit_wrap		= $dom->createElement("div");
		$attr				= $dom->createAttribute("class");
		$attr->value		= "buttons";
		$submit_wrap->appendChild($attr);

		$submit				= $dom->createElement("button", $o["submit_text"]);
		$submit_attr		= $dom->createAttribute("type");
		$submit_attr->value	= "submit";
		$submit->appendChild($submit_attr);
		
		$submit_wrap->appendChild($submit);

		foreach($fields as $name=>$default)
		{
			#do we want to add a new (field)set before this field?
			if(!empty($o["new_set_on"]) && in_array($name, $o["new_set_on"]))
			{
				$form->appendChild($set);

				$set				= $dom->createElement($o["set_element"]);
				$set_attr			= $dom->createAttribute("class");
				$set_count++;
				$set_attr->value	= "elements set-".$set_count.(!empty($o["set_class"])?" $o[set_class]":FALSE);
				$set->appendChild($set_attr);
				if($o["legends"])
				{
					$legend			= $dom->createElement("legend",is_array($o["legends"])?array_shift($o["legends"]):$o["legends"]);
					$set->appendChild($legend);
				}
				
				$wrapper			= $dom->createElement($o["wrap_element"]);
				$set->appendChild($wrapper);
			}
			#get this field's type
			$type		= (isset($o["field_types"][$name])?$o["field_types"][$name]:"text");
			#re/set this flag that says if this is one or many fields we're working with for this one "input".
			$multifields= FALSE;
			$label_last	= FALSE;
			switch($type)
			{
				#catch-all for any field-types.
				default:
					#create a single input field
					$input				= $dom->createElement("input");
				break;
				#build out later
				case "label":
				case "hidden":
				case "disabled":
				break;
				case "select":
					#does this input have multiple field options?
					if(empty($o["field_opts"][$name]))
						{ $o["field_opts"][$name]	= array(0=>"Please Select.."); }
#					$multifields	= TRUE;
					#start a ul & give it a class of type-group
					$input	= $dom->createElement("select");
					$class	= $dom->createAttribute("class");
					$class->value	= "$type-group";
					$input->appendChild($class);

					#append name to this field
					$fname			= $dom->createAttribute("name");
					$fname->value	= $instance.'['.$name.']'.($type=="checkbox"?"[]":FALSE);
					$input->appendChild($fname);

					#loop through all options add them to the ul
#var_dump($o["field_opts"][$name]);die();
					foreach($o["field_opts"][$name] as $value=>$label)<commit_msg>added text-areas... that was easier than I thought<commit_after><?php
#CreatedBy;Aaron;11OCT2014;Odin-Framework
 class bolt_form
{
	var $num_instances	= 0;

	#This is an HTML form that allows you to update/edit database data.
	function create($fields=NULL,$opts=NULL)
	{
		global $odin;
		$this->num_instances++;
		$instance	= (isset($o["instance"])?$o["instance"]:"inst-".$this->num_instances);
		$o			= array(
			"set_element"		=> "fieldset",
			"set_class"			=> "",
			"wrap_element"		=> "ul",
			"item_element"		=> "li",
			"legends"			=> array(),
			"new_set_on"		=> array(),
			"submit_text"		=> "Submit",
			"instance"			=> $instance,
			"field_types"		=> array(),
			"field_opts"		=> array(),
			"form_attrs"		=> array(
				"id"				=> $instance,
				"method"			=> "post",
				"action"			=> $_SERVER["REQUEST_URI"],
			),
		);
		if($opts)
			{ $o	= $odin->array->ow_merge_r($o,$opts); }
		#if fields were not passed, return false
		if(!$fields)
			{ return FALSE; }

		#create the dom object & elements
		$dom		= new DOMDocument();
		$form		= $dom->createElement("form");
		if(!empty($o["form_attrs"]))
		{
			foreach($o["form_attrs"] as $attr=>$value)
			{
				$form_attr			= $dom->createAttribute($attr);
				$form_attr->value	= $value;
				$form->appendChild($form_attr);
			}
		}
		#setup the elements (field)set & wrapper
		$set				= $dom->createElement($o["set_element"]);
		$set_attr			= $dom->createAttribute("class");
		$set_count			= 1;
		$set_attr->value	= "elements set-".$set_count.(!empty($o["set_class"])?" $o[set_class]":FALSE);
		$set->appendChild($set_attr);
		if($o["legends"])
		{
			$legend			= $dom->createElement("legend",is_array($o["legends"])?array_shift($o["legends"]):$o["legends"]);
			$set->appendChild($legend);
		}
		
		$wrapper			= $dom->createElement($o["wrap_element"]);
		$set->appendChild($wrapper);


		#append the submit button into this form, nested inside of its own div.buttons wrapper.
		$submit_wrap		= $dom->createElement("div");
		$attr				= $dom->createAttribute("class");
		$attr->value		= "buttons";
		$submit_wrap->appendChild($attr);

		$submit				= $dom->createElement("button", $o["submit_text"]);
		$submit_attr		= $dom->createAttribute("type");
		$submit_attr->value	= "submit";
		$submit->appendChild($submit_attr);
		
		$submit_wrap->appendChild($submit);

		foreach($fields as $name=>$default)
		{
			#do we want to add a new (field)set before this field?
			if(!empty($o["new_set_on"]) && in_array($name, $o["new_set_on"]))
			{
				$form->appendChild($set);

				$set				= $dom->createElement($o["set_element"]);
				$set_attr			= $dom->createAttribute("class");
				$set_count++;
				$set_attr->value	= "elements set-".$set_count.(!empty($o["set_class"])?" $o[set_class]":FALSE);
				$set->appendChild($set_attr);
				if($o["legends"])
				{
					$legend			= $dom->createElement("legend",is_array($o["legends"])?array_shift($o["legends"]):$o["legends"]);
					$set->appendChild($legend);
				}
				
				$wrapper			= $dom->createElement($o["wrap_element"]);
				$set->appendChild($wrapper);
			}
			#get this field's type
			$type		= (isset($o["field_types"][$name])?$o["field_types"][$name]:"text");
			#re/set this flag that says if this is one or many fields we're working with for this one "input".
			$multifields= FALSE;
			$label_last	= FALSE;
			switch($type)
			{
				#catch-all for any field-types.
				default:
					#create a single input field
					$input				= $dom->createElement("input");
				break;
				#build out later
				case "label":
				case "hidden":
				case "disabled":
				break;
				#textareas
				case "textarea":
					$multifields	= TRUE;
					$input	= $dom->createElement("textarea",$default);
					#set a field name on the attribute
					$fname				= $dom->createAttribute("name");
					$fname->value		= $instance.'['.$name.']';
					$input->appendChild($fname);
				break;
				case "select":
					#does this input have multiple field options?
					if(empty($o["field_opts"][$name]))
						{ $o["field_opts"][$name]	= array(0=>"Please Select.."); }
#					$multifields	= TRUE;
					#start a ul & give it a class of type-group
					$input	= $dom->createElement("select");
					$class	= $dom->createAttribute("class");
					$class->value	= "$type-group";
					$input->appendChild($class);

					#append name to this field
					$fname			= $dom->createAttribute("name");
					$fname->value	= $instance.'['.$name.']'.($type=="checkbox"?"[]":FALSE);
					$input->appendChild($fname);

					#loop through all options add them to the ul
#var_dump($o["field_opts"][$name]);die();
					foreach($o["field_opts"][$name] as $value=>$label)
{'fraction_non_alphanumeric': 0.20303200449185851, 'fraction_numerical': 0.002021336327905671, 'mean_word_length': 3.837588267246062, 'pattern_counts': {'":': 15, '<': 5, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '875742', 'n_tokens_mistral': 3809, 'n_tokens_neox': 3158, 'n_words': 590}