PageRenderTime 369ms CodeModel.GetById 141ms app.highlight 87ms RepoModel.GetById 134ms app.codeStats 1ms

/halogy/helpers/form_helper.php

https://bitbucket.org/haloweb/halogy-1.0/
PHP | 1025 lines | 565 code | 141 blank | 319 comment | 105 complexity | 20fd7b79617297f05e0bd9e72d53a7c3 MD5 | raw file
   1<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
   2/**
   3 * CodeIgniter
   4 *
   5 * An open source application development framework for PHP 4.3.2 or newer
   6 *
   7 * @package		CodeIgniter
   8 * @author		ExpressionEngine Dev Team
   9 * @copyright	Copyright (c) 2008 - 2009, EllisLab, Inc.
  10 * @license		http://codeigniter.com/user_guide/license.html
  11 * @link		http://codeigniter.com
  12 * @since		Version 1.0
  13 * @filesource
  14 */
  15
  16// ------------------------------------------------------------------------
  17
  18/**
  19 * CodeIgniter Form Helpers
  20 *
  21 * @package		CodeIgniter
  22 * @subpackage	Helpers
  23 * @category	Helpers
  24 * @author		ExpressionEngine Dev Team
  25 * @link		http://codeigniter.com/user_guide/helpers/form_helper.html
  26 */
  27
  28// ------------------------------------------------------------------------
  29
  30/**
  31 * Form Declaration
  32 *
  33 * Creates the opening portion of the form.
  34 *
  35 * @access	public
  36 * @param	string	the URI segments of the form destination
  37 * @param	array	a key/value pair of attributes
  38 * @param	array	a key/value pair hidden data
  39 * @return	string
  40 */	
  41if ( ! function_exists('form_open'))
  42{
  43	function form_open($action = '', $attributes = '', $hidden = array())
  44	{
  45		$CI =& get_instance();
  46
  47		if ($attributes == '')
  48		{
  49			$attributes = 'method="post"';
  50		}
  51
  52		$action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action;
  53
  54		$form = '<form action="'.$action.'"';
  55	
  56		$form .= _attributes_to_string($attributes, TRUE);
  57	
  58		$form .= '>';
  59
  60		if (is_array($hidden) AND count($hidden) > 0)
  61		{
  62			$form .= form_hidden($hidden);
  63		}
  64
  65		return $form;
  66	}
  67}
  68
  69// ------------------------------------------------------------------------
  70
  71/**
  72 * Form Declaration - Multipart type
  73 *
  74 * Creates the opening portion of the form, but with "multipart/form-data".
  75 *
  76 * @access	public
  77 * @param	string	the URI segments of the form destination
  78 * @param	array	a key/value pair of attributes
  79 * @param	array	a key/value pair hidden data
  80 * @return	string
  81 */
  82if ( ! function_exists('form_open_multipart'))
  83{
  84	function form_open_multipart($action, $attributes = array(), $hidden = array())
  85	{
  86		$attributes['enctype'] = 'multipart/form-data';
  87		return form_open($action, $attributes, $hidden);
  88	}
  89}
  90
  91// ------------------------------------------------------------------------
  92
  93/**
  94 * Hidden Input Field
  95 *
  96 * Generates hidden fields.  You can pass a simple key/value string or an associative
  97 * array with multiple values.
  98 *
  99 * @access	public
 100 * @param	mixed
 101 * @param	string
 102 * @return	string
 103 */
 104if ( ! function_exists('form_hidden'))
 105{
 106	function form_hidden($name, $value = '', $recursing = FALSE)
 107	{
 108		static $form;
 109
 110		if ($recursing === FALSE)
 111		{
 112			$form = "\n";
 113		}
 114
 115		if (is_array($name))
 116		{
 117			foreach ($name as $key => $val)
 118			{
 119				form_hidden($key, $val, TRUE);
 120			}
 121			return $form;
 122		}
 123
 124		if ( ! is_array($value))
 125		{
 126			$form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value, $name).'" />'."\n";
 127		}
 128		else
 129		{
 130			foreach ($value as $k => $v)
 131			{
 132				$k = (is_int($k)) ? '' : $k; 
 133				form_hidden($name.'['.$k.']', $v, TRUE);
 134			}
 135		}
 136
 137		return $form;
 138	}
 139}
 140
 141// ------------------------------------------------------------------------
 142
 143/**
 144 * Text Input Field
 145 *
 146 * @access	public
 147 * @param	mixed
 148 * @param	string
 149 * @param	string
 150 * @return	string
 151 */
 152if ( ! function_exists('form_input'))
 153{
 154	function form_input($data = '', $value = '', $extra = '')
 155	{
 156		$defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
 157
 158		return "<input "._parse_form_attributes($data, $defaults).$extra." />";
 159	}
 160}
 161
 162// ------------------------------------------------------------------------
 163
 164/**
 165 * Password Field
 166 *
 167 * Identical to the input function but adds the "password" type
 168 *
 169 * @access	public
 170 * @param	mixed
 171 * @param	string
 172 * @param	string
 173 * @return	string
 174 */
 175if ( ! function_exists('form_password'))
 176{
 177	function form_password($data = '', $value = '', $extra = '')
 178	{
 179		if ( ! is_array($data))
 180		{
 181			$data = array('name' => $data);
 182		}
 183
 184		$data['type'] = 'password';
 185		return form_input($data, $value, $extra);
 186	}
 187}
 188
 189// ------------------------------------------------------------------------
 190
 191/**
 192 * Upload Field
 193 *
 194 * Identical to the input function but adds the "file" type
 195 *
 196 * @access	public
 197 * @param	mixed
 198 * @param	string
 199 * @param	string
 200 * @return	string
 201 */
 202if ( ! function_exists('form_upload'))
 203{
 204	function form_upload($data = '', $value = '', $extra = '')
 205	{
 206		if ( ! is_array($data))
 207		{
 208			$data = array('name' => $data);
 209		}
 210
 211		$data['type'] = 'file';
 212		return form_input($data, $value, $extra);
 213	}
 214}
 215
 216// ------------------------------------------------------------------------
 217
 218/**
 219 * Textarea field
 220 *
 221 * @access	public
 222 * @param	mixed
 223 * @param	string
 224 * @param	string
 225 * @return	string
 226 */
 227if ( ! function_exists('form_textarea'))
 228{
 229	function form_textarea($data = '', $value = '', $extra = '')
 230	{
 231		$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
 232
 233		if ( ! is_array($data) OR ! isset($data['value']))
 234		{
 235			$val = $value;
 236		}
 237		else
 238		{
 239			$val = $data['value']; 
 240			unset($data['value']); // textareas don't use the value attribute
 241		}
 242		
 243		$name = (is_array($data)) ? $data['name'] : $data;
 244		return "<textarea "._parse_form_attributes($data, $defaults).$extra.">".form_prep($val, $name)."</textarea>";
 245	}
 246}
 247
 248// ------------------------------------------------------------------------
 249
 250/**
 251 * Multi-select menu
 252 *
 253 * @access	public
 254 * @param	string
 255 * @param	array
 256 * @param	mixed
 257 * @param	string
 258 * @return	type
 259 */
 260if (! function_exists('form_multiselect'))
 261{
 262	function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '')
 263	{
 264		if ( ! strpos($extra, 'multiple'))
 265		{
 266			$extra .= ' multiple="multiple"';
 267		}
 268		
 269		return form_dropdown($name, $options, $selected, $extra);
 270	}
 271}
 272
 273// --------------------------------------------------------------------
 274
 275/**
 276 * Drop-down Menu
 277 *
 278 * @access	public
 279 * @param	string
 280 * @param	array
 281 * @param	string
 282 * @param	string
 283 * @return	string
 284 */
 285if ( ! function_exists('form_dropdown'))
 286{
 287	function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
 288	{
 289		if ( ! is_array($selected))
 290		{
 291			$selected = array($selected);
 292		}
 293
 294		// If no selected state was submitted we will attempt to set it automatically
 295		if (count($selected) === 0)
 296		{
 297			// If the form name appears in the $_POST array we have a winner!
 298			if (isset($_POST[$name]))
 299			{
 300				$selected = array($_POST[$name]);
 301			}
 302		}
 303
 304		if ($extra != '') $extra = ' '.$extra;
 305
 306		$multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
 307
 308		$form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
 309
 310		foreach ($options as $key => $val)
 311		{
 312			$key = (string) $key;
 313
 314			if (is_array($val))
 315			{
 316				$form .= '<optgroup label="'.$key.'">'."\n";
 317
 318				foreach ($val as $optgroup_key => $optgroup_val)
 319				{
 320					$sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : '';
 321
 322					$form .= '<option value="'.$optgroup_key.'"'.$sel.'>'.(string) $optgroup_val."</option>\n";
 323				}
 324
 325				$form .= '</optgroup>'."\n";
 326			}
 327			else
 328			{
 329				$sel = (in_array($key, $selected)) ? ' selected="selected"' : '';
 330
 331				$form .= '<option value="'.$key.'"'.$sel.'>'.(string) $val."</option>\n";
 332			}
 333		}
 334
 335		$form .= '</select>';
 336
 337		return $form;
 338	}
 339}
 340
 341// ------------------------------------------------------------------------
 342
 343/**
 344 * Checkbox Field
 345 *
 346 * @access	public
 347 * @param	mixed
 348 * @param	string
 349 * @param	bool
 350 * @param	string
 351 * @return	string
 352 */
 353if ( ! function_exists('form_checkbox'))
 354{
 355	function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
 356	{
 357		$defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
 358
 359		if (is_array($data) AND array_key_exists('checked', $data))
 360		{
 361			$checked = $data['checked'];
 362
 363			if ($checked == FALSE)
 364			{
 365				unset($data['checked']);
 366			}
 367			else
 368			{
 369				$data['checked'] = 'checked';
 370			}
 371		}
 372
 373		if ($checked == TRUE)
 374		{
 375			$defaults['checked'] = 'checked';
 376		}
 377		else
 378		{
 379			unset($defaults['checked']);
 380		}
 381
 382		return "<input "._parse_form_attributes($data, $defaults).$extra." />";
 383	}
 384}
 385
 386// ------------------------------------------------------------------------
 387
 388/**
 389 * Radio Button
 390 *
 391 * @access	public
 392 * @param	mixed
 393 * @param	string
 394 * @param	bool
 395 * @param	string
 396 * @return	string
 397 */
 398if ( ! function_exists('form_radio'))
 399{
 400	function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
 401	{
 402		if ( ! is_array($data))
 403		{	
 404			$data = array('name' => $data);
 405		}
 406
 407		$data['type'] = 'radio';
 408		return form_checkbox($data, $value, $checked, $extra);
 409	}
 410}
 411
 412// ------------------------------------------------------------------------
 413
 414/**
 415 * Submit Button
 416 *
 417 * @access	public
 418 * @param	mixed
 419 * @param	string
 420 * @param	string
 421 * @return	string
 422 */
 423if ( ! function_exists('form_submit'))
 424{	
 425	function form_submit($data = '', $value = '', $extra = '')
 426	{
 427		$defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
 428
 429		return "<input "._parse_form_attributes($data, $defaults).$extra." />";
 430	}
 431}
 432
 433// ------------------------------------------------------------------------
 434
 435/**
 436 * Reset Button
 437 *
 438 * @access	public
 439 * @param	mixed
 440 * @param	string
 441 * @param	string
 442 * @return	string
 443 */
 444if ( ! function_exists('form_reset'))
 445{
 446	function form_reset($data = '', $value = '', $extra = '')
 447	{
 448		$defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
 449
 450		return "<input "._parse_form_attributes($data, $defaults).$extra." />";
 451	}
 452}
 453
 454// ------------------------------------------------------------------------
 455
 456/**
 457 * Form Button
 458 *
 459 * @access	public
 460 * @param	mixed
 461 * @param	string
 462 * @param	string
 463 * @return	string
 464 */
 465if ( ! function_exists('form_button'))
 466{
 467	function form_button($data = '', $content = '', $extra = '')
 468	{
 469		$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button');
 470
 471		if ( is_array($data) AND isset($data['content']))
 472		{
 473			$content = $data['content'];
 474			unset($data['content']); // content is not an attribute
 475		}
 476
 477		return "<button "._parse_form_attributes($data, $defaults).$extra.">".$content."</button>";
 478	}
 479}
 480
 481// ------------------------------------------------------------------------
 482
 483/**
 484 * Form Label Tag
 485 *
 486 * @access	public
 487 * @param	string	The text to appear onscreen
 488 * @param	string	The id the label applies to
 489 * @param	string	Additional attributes
 490 * @return	string
 491 */
 492if ( ! function_exists('form_label'))
 493{
 494	function form_label($label_text = '', $id = '', $attributes = array())
 495	{
 496
 497		$label = '<label';
 498
 499		if ($id != '')
 500		{
 501			 $label .= " for=\"$id\"";
 502		}
 503
 504		if (is_array($attributes) AND count($attributes) > 0)
 505		{
 506			foreach ($attributes as $key => $val)
 507			{
 508				$label .= ' '.$key.'="'.$val.'"';
 509			}
 510		}
 511
 512		$label .= ">$label_text</label>";
 513
 514		return $label;
 515	}
 516}
 517
 518// ------------------------------------------------------------------------
 519/**
 520 * Fieldset Tag
 521 *
 522 * Used to produce <fieldset><legend>text</legend>.  To close fieldset
 523 * use form_fieldset_close()
 524 *
 525 * @access	public
 526 * @param	string	The legend text
 527 * @param	string	Additional attributes
 528 * @return	string
 529 */
 530if ( ! function_exists('form_fieldset'))
 531{
 532	function form_fieldset($legend_text = '', $attributes = array())
 533	{
 534		$fieldset = "<fieldset";
 535
 536		$fieldset .= _attributes_to_string($attributes, FALSE);
 537
 538		$fieldset .= ">\n";
 539
 540		if ($legend_text != '')
 541		{
 542			$fieldset .= "<legend>$legend_text</legend>\n";
 543		}
 544
 545		return $fieldset;
 546	}
 547}
 548
 549// ------------------------------------------------------------------------
 550
 551/**
 552 * Fieldset Close Tag
 553 *
 554 * @access	public
 555 * @param	string
 556 * @return	string
 557 */
 558if ( ! function_exists('form_fieldset_close'))
 559{
 560	function form_fieldset_close($extra = '')
 561	{
 562		return "</fieldset>".$extra;
 563	}
 564}
 565
 566// ------------------------------------------------------------------------
 567
 568/**
 569 * Form Close Tag
 570 *
 571 * @access	public
 572 * @param	string
 573 * @return	string
 574 */
 575if ( ! function_exists('form_close'))
 576{
 577	function form_close($extra = '')
 578	{
 579		return "</form>".$extra;
 580	}
 581}
 582
 583// ------------------------------------------------------------------------
 584
 585/**
 586 * Form Prep
 587 *
 588 * Formats text so that it can be safely placed in a form field in the event it has HTML tags.
 589 *
 590 * @access	public
 591 * @param	string
 592 * @return	string
 593 */
 594if ( ! function_exists('form_prep'))
 595{
 596	function form_prep($str = '', $field_name = '')
 597	{
 598		static $prepped_fields = array();
 599		
 600		// if the field name is an array we do this recursively
 601		if (is_array($str))
 602		{
 603			foreach ($str as $key => $val)
 604			{
 605				$str[$key] = form_prep($val);
 606			}
 607
 608			return $str;
 609		}
 610
 611		if ($str === '')
 612		{
 613			return '';
 614		}
 615
 616		// we've already prepped a field with this name
 617		// @todo need to figure out a way to namespace this so
 618		// that we know the *exact* field and not just one with
 619		// the same name
 620		if (isset($prepped_fields[$field_name]))
 621		{
 622			return $str;
 623		}
 624		
 625		$str = htmlspecialchars($str);
 626
 627		// In case htmlspecialchars misses these.
 628		$str = str_replace(array("'", '"'), array("&#39;", "&quot;"), $str);
 629
 630		if ($field_name != '')
 631		{
 632			$prepped_fields[$field_name] = $str;
 633		}
 634		
 635		return $str;
 636	}
 637}
 638
 639// ------------------------------------------------------------------------
 640
 641/**
 642 * Form Value
 643 *
 644 * Grabs a value from the POST array for the specified field so you can
 645 * re-populate an input field or textarea.  If Form Validation
 646 * is active it retrieves the info from the validation class
 647 *
 648 * @access	public
 649 * @param	string
 650 * @return	mixed
 651 */
 652if ( ! function_exists('set_value'))
 653{
 654	function set_value($field = '', $default = '')
 655	{
 656		if (FALSE === ($OBJ =& _get_validation_object()))
 657		{
 658			if ( ! isset($_POST[$field]))
 659			{
 660				return $default;
 661			}
 662
 663			return form_prep($_POST[$field], $field);
 664		}
 665
 666		return form_prep($OBJ->set_value($field, $default), $field);
 667	}
 668}
 669
 670// ------------------------------------------------------------------------
 671
 672/**
 673 * Set Select
 674 *
 675 * Let's you set the selected value of a <select> menu via data in the POST array.
 676 * If Form Validation is active it retrieves the info from the validation class
 677 *
 678 * @access	public
 679 * @param	string
 680 * @param	string
 681 * @param	bool
 682 * @return	string
 683 */
 684if ( ! function_exists('set_select'))
 685{
 686	function set_select($field = '', $value = '', $default = FALSE)
 687	{
 688		$OBJ =& _get_validation_object();
 689
 690		if ($OBJ === FALSE)
 691		{
 692			if ( ! isset($_POST[$field]))
 693			{
 694				if (count($_POST) === 0 AND $default == TRUE)
 695				{
 696					return ' selected="selected"';
 697				}
 698				return '';
 699			}
 700
 701			$field = $_POST[$field];
 702
 703			if (is_array($field))
 704			{
 705				if ( ! in_array($value, $field))
 706				{
 707					return '';
 708				}
 709			}
 710			else
 711			{
 712				if (($field == '' OR $value == '') OR ($field != $value))
 713				{
 714					return '';
 715				}
 716			}
 717
 718			return ' selected="selected"';
 719		}
 720
 721		return $OBJ->set_select($field, $value, $default);
 722	}
 723}
 724
 725// ------------------------------------------------------------------------
 726
 727/**
 728 * Set Checkbox
 729 *
 730 * Let's you set the selected value of a checkbox via the value in the POST array.
 731 * If Form Validation is active it retrieves the info from the validation class
 732 *
 733 * @access	public
 734 * @param	string
 735 * @param	string
 736 * @param	bool
 737 * @return	string
 738 */
 739if ( ! function_exists('set_checkbox'))
 740{
 741	function set_checkbox($field = '', $value = '', $default = FALSE)
 742	{
 743		$OBJ =& _get_validation_object();
 744
 745		if ($OBJ === FALSE)
 746		{ 
 747			if ( ! isset($_POST[$field]))
 748			{
 749				if (count($_POST) === 0 AND $default == TRUE)
 750				{
 751					return ' checked="checked"';
 752				}
 753				return '';
 754			}
 755
 756			$field = $_POST[$field];
 757			
 758			if (is_array($field))
 759			{
 760				if ( ! in_array($value, $field))
 761				{
 762					return '';
 763				}
 764			}
 765			else
 766			{
 767				if (($field == '' OR $value == '') OR ($field != $value))
 768				{
 769					return '';
 770				}
 771			}
 772
 773			return ' checked="checked"';
 774		}
 775
 776		return $OBJ->set_checkbox($field, $value, $default);
 777	}
 778}
 779
 780// ------------------------------------------------------------------------
 781
 782/**
 783 * Set Radio
 784 *
 785 * Let's you set the selected value of a radio field via info in the POST array.
 786 * If Form Validation is active it retrieves the info from the validation class
 787 *
 788 * @access	public
 789 * @param	string
 790 * @param	string
 791 * @param	bool
 792 * @return	string
 793 */
 794if ( ! function_exists('set_radio'))
 795{
 796	function set_radio($field = '', $value = '', $default = FALSE)
 797	{
 798		$OBJ =& _get_validation_object();
 799
 800		if ($OBJ === FALSE)
 801		{
 802			if ( ! isset($_POST[$field]))
 803			{
 804				if (count($_POST) === 0 AND $default == TRUE)
 805				{
 806					return ' checked="checked"';
 807				}
 808				return '';
 809			}
 810
 811			$field = $_POST[$field];
 812			
 813			if (is_array($field))
 814			{
 815				if ( ! in_array($value, $field))
 816				{
 817					return '';
 818				}
 819			}
 820			else
 821			{
 822				if (($field == '' OR $value == '') OR ($field != $value))
 823				{
 824					return '';
 825				}
 826			}
 827
 828			return ' checked="checked"';
 829		}
 830
 831		return $OBJ->set_radio($field, $value, $default);
 832	}
 833}
 834
 835// ------------------------------------------------------------------------
 836
 837/**
 838 * Form Error
 839 *
 840 * Returns the error for a specific form field.  This is a helper for the
 841 * form validation class.
 842 *
 843 * @access	public
 844 * @param	string
 845 * @param	string
 846 * @param	string
 847 * @return	string
 848 */
 849if ( ! function_exists('form_error'))
 850{
 851	function form_error($field = '', $prefix = '', $suffix = '')
 852	{
 853		if (FALSE === ($OBJ =& _get_validation_object()))
 854		{
 855			return '';
 856		}
 857
 858		return $OBJ->error($field, $prefix, $suffix);
 859	}
 860}
 861
 862// ------------------------------------------------------------------------
 863
 864/**
 865 * Validation Error String
 866 *
 867 * Returns all the errors associated with a form submission.  This is a helper
 868 * function for the form validation class.
 869 *
 870 * @access	public
 871 * @param	string
 872 * @param	string
 873 * @return	string
 874 */
 875if ( ! function_exists('validation_errors'))
 876{
 877	function validation_errors($prefix = '', $suffix = '')
 878	{
 879		if (FALSE === ($OBJ =& _get_validation_object()))
 880		{
 881			return '';
 882		}
 883
 884		return $OBJ->error_string($prefix, $suffix);
 885	}
 886}
 887
 888// ------------------------------------------------------------------------
 889
 890/**
 891 * Parse the form attributes
 892 *
 893 * Helper function used by some of the form helpers
 894 *
 895 * @access	private
 896 * @param	array
 897 * @param	array
 898 * @return	string
 899 */
 900if ( ! function_exists('_parse_form_attributes'))
 901{
 902	function _parse_form_attributes($attributes, $default)
 903	{
 904		if (is_array($attributes))
 905		{
 906			foreach ($default as $key => $val)
 907			{
 908				if (isset($attributes[$key]))
 909				{
 910					$default[$key] = $attributes[$key];
 911					unset($attributes[$key]);
 912				}
 913			}
 914
 915			if (count($attributes) > 0)
 916			{
 917				$default = array_merge($default, $attributes);
 918			}
 919		}
 920
 921		$att = '';
 922		
 923		foreach ($default as $key => $val)
 924		{
 925			if ($key == 'value')
 926			{
 927				$val = form_prep($val, $default['name']);
 928			}
 929
 930			$att .= $key . '="' . $val . '" ';
 931		}
 932
 933		return $att;
 934	}
 935}
 936
 937// ------------------------------------------------------------------------
 938
 939/**
 940 * Attributes To String
 941 *
 942 * Helper function used by some of the form helpers
 943 *
 944 * @access	private
 945 * @param	mixed
 946 * @param	bool
 947 * @return	string
 948 */
 949if ( ! function_exists('_attributes_to_string'))
 950{
 951	function _attributes_to_string($attributes, $formtag = FALSE)
 952	{
 953		if (is_string($attributes) AND strlen($attributes) > 0)
 954		{
 955			if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE)
 956			{
 957				$attributes .= ' method="post"';
 958			}
 959
 960		return ' '.$attributes;
 961		}
 962	
 963		if (is_object($attributes) AND count($attributes) > 0)
 964		{
 965			$attributes = (array)$attributes;
 966		}
 967
 968		if (is_array($attributes) AND count($attributes) > 0)
 969		{
 970		$atts = '';
 971
 972		if ( ! isset($attributes['method']) AND $formtag === TRUE)
 973		{
 974			$atts .= ' method="post"';
 975		}
 976
 977		foreach ($attributes as $key => $val)
 978		{
 979			$atts .= ' '.$key.'="'.$val.'"';
 980		}
 981
 982		return $atts;
 983		}
 984	}
 985}
 986
 987// ------------------------------------------------------------------------
 988
 989/**
 990 * Validation Object
 991 *
 992 * Determines what the form validation class was instantiated as, fetches
 993 * the object and returns it.
 994 *
 995 * @access	private
 996 * @return	mixed
 997 */
 998if ( ! function_exists('_get_validation_object'))
 999{
1000	function &_get_validation_object()
1001	{
1002		$CI =& get_instance();
1003
1004		// We set this as a variable since we're returning by reference
1005		$return = FALSE;
1006
1007		if ( ! isset($CI->load->_ci_classes) OR  ! isset($CI->load->_ci_classes['form_validation']))
1008		{
1009			return $return;
1010		}
1011
1012		$object = $CI->load->_ci_classes['form_validation'];
1013
1014		if ( ! isset($CI->$object) OR ! is_object($CI->$object))
1015		{
1016			return $return;
1017		}
1018
1019		return $CI->$object;
1020	}
1021}
1022
1023
1024/* End of file form_helper.php */
1025/* Location: ./system/helpers/form_helper.php */