폼(form) Sample

<?php
/**
 * Form helper
 *
 * Created on 2011. 11. 18.
 * @author 불의회상 <hoksi2k@hanmail.net>
 * @package helper
 * @subpackage controllers
 * @version 1.0
 */
class Form_hlp extends CI_Controller {
	function __construct()
	{
		parent::__construct();
		
		$this->load->helper('form');
	}
	
	function index() {
		// Default
		$data['form_open_default'] = form_open();

		// Action 변경
		$data['form_open_action'] = form_open('form_hlp/add');
		
		// Multipart Form
		$data['form_open_multipart'] = form_open_multipart();
		
		// Hidden field
		$data['form_hidden'] = form_hidden('username', 'johndoe');

		// View form config
		$data['attr'] = array('class' => 'form_cls', 'id' => 'myform', 'name' => 'myform');
		$data['hidden'] = array('username' => 'Joe', 'member_id' => '234');
		
		$data['input'] = array(
			'name'        => 'username',
			'id'          => 'username',
			'value'       => 'johndoe',
			'maxlength'   => '100',
			'size'        => '30',
			'style'       => 'width:30%'
		);
		
		$data['options'] = array(
			'small'		=> 'Small Shirt',
			'med'		=> 'Medium Shirt',
			'large'		=> 'Large Shirt',
			'xlarge'	=> 'Extra Large Shirt'
		);
		
		$data['chk_opt'] = array(
			'name'        => 'newsletter',
			'id'          => 'newsletter',
			'value'       => 'accept',
			'checked'     => TRUE,
			'style'       => 'margin:10px'
		);
		
		$data['btn_opt'] = array(
			'name' => 'button',
			'id' => 'button',
			'value' => 'true',
			'type' => 'reset',
			'content' => 'Reset'
		);
		
		// JavaScript
		$data['js'] = 'onClick="some_function()"';
		$data['seljs'] = 'onChange="some_function()"';
		// String
		$data['string'] = 'Here is a string containing "quoted" text.';
		
		$this->load->view('form_hlp_sample', $data);
	}
}
<?php $this->load->view('inc/header')?>

<table class="tablesorter" border="0" cellpadding="0" cellspacing="1">
<thead>
<tr>
  <th style="text-align:center" width="20%">구분</th>
  <th width="80%">결과</th>
</tr>
</thead>
<tr>
  <th style="text-align:center" colspan="2">Form Option</th>
</tr>
<tr>
	<td>$attr</td>
	<td><xmp><?php print_r($attr)?></xmp></td>
</tr>
<tr>
	<td>$hidden</td>
	<td><xmp><?php print_r($hidden)?></xmp></td>
</tr>
<tr>
	<td>$string</td>
	<td><xmp><?php print_r($string)?></xmp></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Form</th>
</tr>
<tr>
	<td>form_open()</td>
	<td><xmp><?php echo $form_open_default?></xmp></td>
</tr>
<tr>
	<td>form_open('form_hlp/add')</td>
	<td><xmp><?php echo $form_open_action?></xmp></td>
</tr>
<tr>
	<td>form_open(NULL, $attr)</td>
	<td><xmp><?php echo form_open(NULL, $attr)?></xmp></td>
</tr>
<tr>
	<td>form_open(NULL, $attr, $hidden)</td>
	<td><xmp><?php echo form_open(NULL, $attr, $hidden)?></xmp></td>
</tr>
<tr>
	<td>form_open_multipart()</td>
	<td><xmp><?php echo $form_open_multipart?></xmp>form_open() 와 동일하나 multipart 속성을 추가한다</td>
</tr>
<tr>
	<td>form_hidden('username', 'johndoe')</td>
	<td><xmp><?php echo $form_hidden?></xmp></td>
</tr>
<tr>
	<td>form_hidden($hidden)</td>
	<td><xmp><?php echo form_hidden($hidden)?></xmp></td>
</tr>
<tr>
	<td>form_close($string)</td>
	<td><xmp><?php echo form_close($string)?></xmp></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Input Option</th>
</tr>
<tr>
	<td>$input</td>
	<td><xmp><?php print_r($input)?></xmp></td>
</tr>
<tr>
	<td>$js</td>
	<td><?php echo $js?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Input</th>
</tr>
<tr>
	<td>form_input('username', 'johndoe')</td>
	<td><?php echo form_input('username', 'johndoe')?></td>
</tr>
<tr>
	<td>form_password($input)</td>
	<td><?php echo form_password($input)?></td>
</tr>
<tr>
<tr>
	<td>form_upload($input, NULL, $js)</td>
	<td><?php echo form_upload($input, NULL, $js)?></td>
</tr>
<tr>
	<td>form_textarea($input)</td>
	<td><?php echo form_textarea($input)?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Select Option</th>
</tr>
<tr>
	<td>$options</td>
	<td><xmp><?php print_r($options)?></xmp></td>
</tr>
<tr>
	<td>$seljs</td>
	<td><?php echo $seljs?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Select</th>
</tr>
<tr>
	<td>form_dropdown('shirts', $options, 'large')</td>
	<td><?php echo form_dropdown('shirts', $options, 'large')?></td>
</tr>
<tr>
	<td>form_dropdown('shirts', $options, array('small', 'large'))</td>
	<td><?php echo form_dropdown('shirts', $options, array('small', 'large'))?></td>
</tr>
<tr>
	<td>form_dropdown('shirts', $options, 'large', $seljs)</td>
	<td><?php echo form_dropdown('shirts', $options, 'large', $seljs)?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Checkbox, Radio Option</th>
</tr>
<tr>
	<td>$chk_opt</td>
	<td><xmp><?php print_r($chk_opt)?></xmp></td>
</tr>
<tr>
	<td>$js</td>
	<td><?php echo $js?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Checkbox, Radio</th>
</tr>
<tr>
	<td>form_checkbox('newsletter', 'accept', TRUE)</td>
	<td><?php echo form_checkbox('newsletter', 'accept', TRUE)?></td>
</tr>
<tr>
	<td>form_radio($chk_opt)</td>
	<td><?php echo form_radio($chk_opt)?></td>
</tr>
<tr>
	<td>form_radio($chk_opt, NULL, NULL, $js)</td>
	<td><?php echo form_radio($chk_opt, NULL, NULL, $js)?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Label</th>
</tr>
<tr>
	<td>form_label('What is your Name', 'username')</td>
	<td><xmp><?php echo form_label('What is your Name', 'username')?></xmp></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Button Option</th>
</tr>
<tr>
	<td>$btn_opt</td>
	<td><xmp><?php print_r($btn_opt)?></xmp></td>
</tr>
<tr>
	<td>$js</td>
	<td><?php echo $js?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Button</th>
</tr>
<tr>
	<td>form_submit('mysubmit', 'Submit Post!')</td>
	<td><?php echo form_submit('mysubmit', 'Submit Post!')?></td>
</tr>
<tr>
	<td>form_reset('myreset', 'Reset Post!')</td>
	<td><?php echo form_reset('myreset', 'Reset Post!')?></td>
</tr>
<tr>
	<td>form_button('name','content')</td>
	<td><?php echo form_button('name','content')?></td>
</tr>
<tr>
	<td>form_button($btn_opt)</td>
	<td><?php echo form_button($btn_opt)?></td>
</tr>
<tr>
	<td>form_button('mybutton', 'Click Me', $js)</td>
	<td><?php echo form_button('mybutton', 'Click Me', $js)?></td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Fieldset</th>
</tr>
<tr>
	<td rowspan="2">
		form_fieldset()<br/>
		form_fieldset_close()
	</td>
	<td><?php
		echo form_fieldset('Address Information');
		echo "<p>fieldset content here</p>\n";
		echo form_fieldset_close();
		?>
	</td>
</tr>
<tr>
	<td><?php
		echo form_fieldset('Address Information', array('id' => 'address_info', 'class' => 'address_info'));
		echo "<p>fieldset content here</p>\n";
		echo form_fieldset_close(); 
		?>
	</td>
</tr>
<tr>
  <th style="text-align:center" colspan="2">Etc</th>
</tr>
<tr>
	<td>form_prep($string)</td>
	<td><xmp><?php echo form_prep($string)?></xmp></td>
</tr>
<tr>
	<td>set_value()</td>
	<td><input type="text" name="quantity" value="<?php echo set_value('quantity', '0'); ?>" size="50" /></td>
</tr>
<tr>
	<td>set_select()</td>
	<td>
		<select name="myselect">
		<option value="one" <?php echo set_select('myselect', 'one', TRUE); ?> >One</option>
		<option value="two" <?php echo set_select('myselect', 'two'); ?> >Two</option>
		<option value="three" <?php echo set_select('myselect', 'three'); ?> >Three</option>
		</select>
	</td>
</tr>
<tr>
	<td>set_checkbox()</td>
	<td>
		<input type="checkbox" name="mycheck" value="1" <?php echo set_checkbox('mycheck', '1'); ?> />
		<input type="checkbox" name="mycheck" value="2" <?php echo set_checkbox('mycheck', '2'); ?> />
	</td>
</tr>
<tr>
	<td>set_radio()</td>
	<td>
		<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
		<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />
	</td>
</tr>
</table>

<?php $this->load->view('inc/footer')?>

© Copyright by hoksi(Page rendered in 0.0150 seconds)