CodeIgniter Form Helper
Saturday, 12 June 2010 00:54
CI ရဲ႕ form helper အေၾကာင္းကို ဆက္ေရးပါမယ္။ ျပီးခဲ့တဲ့ post မွာ CI database library အေၾကာင္းကို ေရးခဲ့ပါတယ္။ ဒီ form helper
ျပီးရင္ေတာ့ simple data entry, browse data စတာေတြကို ေရးၾကည့္လို႕ ရပါျပီး။ ဒီ form helper ကေတာ့ view ထဲမွာ ေရးရမယ့္ user interface
နဲ႔ ဆိုင္တဲ့ coding ေတြပဲ ျဖစ္ပါတယ္။ ကြၽန္ေတာ္တို႔ ေရးေနၾက html code ေတြကို CI form helper ကဘယ္လို control လုပ္သြားတယ္ ဆိုတာ
ၾကည့္လိုက္ရေအာင္
form_open()
echo form_open('welcome/search');
ကေတာ့ html မွာ <form method="post" action="http:/example.com/index.php/welcome/search" />
နဲ႔ အတူတူပဲ ျဖစ္ပါတယ္။ From မွာ attribute ေတြျဖစ္တဲ့ CSS class name ေတြ form id ေတြကို ထည့္ခ်င္ရင္ေတာ့
$attributes = array('class' => 'welcome', 'id' => 'myform');
echo form_open('welcome/search', $attributes);
html မွာ ဆိုရင္
<form method="post" action="http:/example.com/index.php/welcome/search" class="welcome" id="myform" />
form_hidden()
Form မွာ hidden value ေတြထည့္ ခ်င္ရင္ေတာ့ form_hidden ကိုသုံးႏိုင္ပါတယ္။
form_hidden('username', 'zack');
form_input()
html မွာ သုံးတဲ့ input ေတြအားလုံးကိုသုံးဖို႔ form_input ကကူညီပါလိမ့္မယ္။ $data = array(
'name' =>'searchterm',
'id' = > 'search',
'maxlength' = > '100',
'size' = > '50',
'style' = > 'background-color:#f1f1f1'
)
echo form_input($data);
html code ကေတာ့
<input type="text" name="searchterm" id="search" maxlength="100" size="50" style="background-color:#f1f1f1" />
form_password() ကေတာ့ password အတြက္ ျဖစ္ျပီး form_textarea() ကေတာ့ textarea အတြက္ သုံးႏိုင္ပါတယ္။ ဒါအျပင္
form_upload() ကလည္း file upload အတြက္ ျဖစ္ပါတယ္။ $options = array( $data = array( echo form_submit('mysubmit', 'Submit Post!');
form_dropdown() ကေတာ့ combo box (or) dropdown list အတြက္ပါ။
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
echo form_dropdown('shirts', $options, 'large');
html code:
<select name="shirts">
<option value="small">Small Shirt</option>
<option value="med">Medium Shirt</option>
<option value="large" selected="selected">Large Shirt</option>
<option value="xlarge">Extra Large Shirt</option>
</select>
form_checkbox() ကေတာ့ checkbox အတြက္ပါ။
'name' => 'newsletter',
'id' => 'newsletter',
'value' => 'accept',
'checked' => TRUE,
'style' => 'margin:10px',
);
echo form_checkbox($data);
html code:
<input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" />
form_radio() ကလည္း form_checkbox() usage အတိုင္းပဲ ျဖစ္ပါတယ္။
form_submit() ဆိုတာကေတာ့ submit button အတြက္ပါ။
html code:
<input type="submit" name="mysubmit" value="Submit Post!" />
submit မဟုတ္ေသာ တျခား button မ်ားအတြက္ form_button() ရွိပါတယ္။ form_reset() ကေတာ့ reset button အတြက္ ျဖစ္ပါတယ္။
form_close() ကေတာ့ form tab ကိုျပန္ပိတ္ဖို႔ပါ။ ကဲဒီေလာက္ဆိုရင္ form helper က function ေတြစုံသေလာက္ ျဖစ္သြားျပီဗ်ာ။
က်န္လည္း နည္းနည္းေပါ့။ program ေရးရင္း ေတြ႔ရင္ ျပန္ထည့္သြားပါမယ္။ ေနာက္ post မွာ database entry page ကိုေရးၾကည့္မယ္။
ခုေတာ့ နားလိုက္ပါအံုးမယ္။ ဆက္ဖတ္သင့္ေသာ Posts မ်ား
-
CodeIgniter and MVC for Beginners
-
Structure and Configuration of CodeIgniter
- CodeIgniter Database Library
-
MVC (SaturnGod)
| < Prev | Next > |
|---|
Login Form
Latest Post
Categories Table View
- Reader's Conner (133)
- PHP (48)
- Joomla CMS (46)
- Codeigniter (18)
- jQuery (12)
- iDhamma (11)
- Mobile Development (10)
- PHP & AJAX (4)
- Apache (3)
- For Mac (3)
- mySQL (2)
- DhammaDroid (1)