-
CakePHP 1.2 FormHelper Examples(1) - [php]
2008-07-20
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://lonelyteers.blogbus.com/logs/25083597.html
CakePHP 1.2 FormHelper Examples
Posted here are live examples. Both the generated code and the rendered examples are running live on this server.
create
You write this …
<?php echo $form->create('Model',array('default' => false)); ?>… and CakePHP returns this …
<form id="ModelAddForm" method="post" action="/cake1point2/models/add/" onSubmit="return false;">… which begins your form.
end
You write this …
<?php echo $form->end();?>; ?>… and CakePHP returns this …
</form>… which ends your form.
label
You write this …
<?php echo $form->label('Contacts.firstName','First Name',null); ?>… and CakePHP returns this …
<label for="ContactsFirstName">First Name</label>… which renders (as I have it styled) as this:
First Name
input
You write this …
<?php echo $form->input('firstName'); ?>… and CakePHP returns this …
<div class="input"><label for="ContactsFirstName">FirstName</label><input name="data[Contacts][firstName]" type="text" value="" id="ContactsFirstName" /></div>… which renders (as I have it styled) as this:
FirstName
inputs
You write this …
<?php echo $form->inputs(array('firstName','lastName','middleName'),array('middleName')); ?>… and CakePHP returns this …
<fieldset><legend>New Contacts</legend><div class="input"><label for="ContactsFirstName">FirstName</label><input name="data[Contacts][firstName]" type="text" value="" id="ContactsFirstName" /></div><div class="input"><label for="ContactsLastName">LastName</label><input name="data[Contacts][lastName]" type="text" value="" id="ContactsLastName" /></div></fieldset>… which renders (as I have it styled) as this:
checkbox
You write this …
<?php echo $form->checkbox('Contacts.firstName'); ?>… and CakePHP returns this …
<input type="hidden" name="data[Contacts][firstName]" value="0" id="ContactsFirstName_" /><input type="checkbox" name="data[Contacts][firstName]" type="checkbox" value="1" id="ContactsFirstName" />… which renders (as I have it styled) as this:
radio
You write this …
<?php echo $form->radio('Contacts.firstName',array('yes','no')); ?>… and CakePHP returns this …
<input type="radio" name="data[Contacts][firstName]" id="firstName_0" id="ContactsFirstName" value="0" checked="checked" />yes<input type="radio" name="data[Contacts][firstName]" id="firstName_1" id="ContactsFirstName" value="1" />no… which renders (as I have it styled) as this:
yes
notext
You write this …
<?php echo $form->text('Contacts.firstName'); ?>… and CakePHP returns this …
<input name="data[Contacts][firstName]" type="text" value="" id="ContactsFirstName" />… which renders (as I have it styled) as this:
password
You write this …
<?php echo $form->password('Contacts.password'); ?>… and CakePHP returns this …
<input type="password" name="data[Contacts][password]" value="" id="ContactsPassword" />… which renders (as I have it styled) as this:
textarea
You write this …
<?php echo $form->textarea('Contacts.comments',array('rows'=>'10','cols'=>'50')); ?>… and CakePHP returns this …
<textarea name="data[Contacts][comments]" rows="10" cols="50" id="ContactsComments"></textarea>… which renders (as I have it styled) as this:
hidden
You write this …
<?php echo $form->hidden('Contacts.status'); ?>… and CakePHP returns this …
<input type="hidden" name="data[Contacts][status]" value="" id="ContactsStatus" />… which renders (as I have it styled) as this:
file
You write this …
<?php echo $form->file('Contacts.attached'); ?>… and CakePHP returns this …
<input type="file" name="data[Contacts][attached]" value="" id="ContactsAttached" />… which renders (as I have it styled) as this:
submit
You write this …
<?php echo $form->submit('Submit'); ?>… and CakePHP returns this …
<div class="submit"><input type="submit" value="Submit" /></div>… which renders (as I have it styled) as this:
submitImage
You write this …
<?php echo $form->submitImage('cake.icon.png'); ?>… and CakePHP returns this …
<input type="image" src="/cake1point2/img/cake.icon.png" />… which renders (as I have it styled) as this:
select
You write this …
<?php echo $form->select('Contacts.type',array('vendor'=>'vendor','subcontractor'=>'subcontractor','employee'=>'employee'),'vendor',null,false); ?>… and CakePHP returns this …
<select name="data[Contacts][type]" id="ContactsType">
<option value="vendor" selected="selected">vendor</option>
<option value="subcontractor">subcontractor</option>
<option value="employee">employee</option>
</select>… which renders (as I have it styled) as this:
随机文章:
CakePHP 1.2 FormHelper Examples(2) 2008-07-20美国是班长,中国是团支书,太强了(转) 2008-07-04php5.0提供的_get()和_set()方法 2008-06-30mysql 类型 2008-06-18pdo 2008-06-17
收藏到:Del.icio.us





