Tuesday, 24 December 2013

Cakephp Form Helper

How to make dynamic value in link

<?php echo $html->link($post['Member']['name'],array('action'=>view,$post['Member']['id']));?>

How to make Cakephp form with form helper

<?php echo $this->Form->create('Member', array('class' => 'form-horizontal')); ?>
echo $this->Form->create('User', array('type' => 'file'));
<form id="UserAddForm" enctype="multipart/form-data"
   method="post" action="/users/add">
echo $this->Form->create(null, array(
    'url' => 'http://www.google.com/search',
    'type' => 'get'
));


<form method="get" action="http://www.google.com/search">
Notes:
 # Create Form.
# Here Member is model name

<?php echo $this->Html->tag('label', 'Name', array('class' => 'col-sm-4 control-label'));?>
echo $this->Form->label('User.name', 'Your username', 'highlight');
<label for="UserName" class="highlight">Your username</label>
Notes:
# Create Label with Name level & its class.

<?php echo $this->Form->input('Member.firstname', array('type' => 'text','class'=>'form-control margin_bottom','placeholder'=>'First','label' => false,'div'=>array('class'=>'col-sm-4'))); ?>

echo $this->Form->input('birth_dt', array(
    'label' => 'Date of birth',
    'dateFormat' => 'DMY',
    'minYear' => date('Y') - 70,
    'maxYear' => date('Y') - 18,
));
echo $this->Form->input('Modelname.0.fieldname');
<input type="text" id="Modelname0Fieldname" name="data[Modelname][0][fieldname]"> 
echo $this->Form->text('username', array('class' => 'users'));
<input name="data[User][username]" type="text" class="users"
    id="UserUsername" />
echo $this->Form->password('password');


<input name="data[User][password]" value="" id="UserPassword" type="password" />
echo $this->Form->hidden('id');


<input name="data[User][id]" id="UserId" type="hidden" />
echo $this->Form->checkbox('done', array('value' => 555));
<input type="checkbox" name="data[User][done]" value="555" id="UserDone" />
Notes:
# Create input field type text with id MemberFirstname , name is data[Member][firstname].
# By default label is false.
# input field is inside div with class.

<?php echo $this->Form->input('Register',array('class'=>'sign_in button_reg','type'=>'submit','label'=>false)); ?>

$options = array('M' => 'Male', 'F' => 'Female');
$attributes = array('legend' => false);
echo $this->Form->radio('gender', $options, $attributes);
<input name="data[User][gender]" id="UserGender_" value=""
    type="hidden" />
<input name="data[User][gender]" id="UserGenderM" value="M"
    type="radio" />
<label for="UserGenderM">Male</label>
<input name="data[User][gender]" id="UserGenderF" value="F"
    type="radio" />
<label for="UserGenderF">Female</label>


Notes:
# Create input type submit with name registrer

echo $this->Form->input('field', array(
    'options' => array(1, 2, 3, 4, 5),
    'empty' => '(choose one)'
));
<div class="input">
    <label for="UserField">Field</label>
    <select name="data[User][field]" id="UserField">
        <option value="">(choose one)</option>
        <option value="0">1</option>
        <option value="1">2</option>
        <option value="2">3</option>
        <option value="3">4</option>
        <option value="4">5</option>
    </select>
</div>
$options=array('G1'=>'General','G2'=>'Advanced');
echo $this->Form->input('Select',array('type'=>'select','option'=>$options,'selected'=>'G2'));

<?php echo $this->Form->end();?>

Notes:
# End the form

0 comments:

Post a Comment