Skip to main content

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

Comments

Popular posts from this blog

Generate XML file in Cakephp

Steps to Generate XML file using CakePHP: Step-1 Enable to parse xml extension in config route.php file.     Router::parseExtensions('xml'); Step-2 Add Request Handler Component to the Controller    var $components = array(‘RequestHandler’); Step-3 Add controller Action For XML Generation in Post Controller     function generateXMLFile()     {         if ($this->RequestHandler->isXml()) { // check request type             $this->layout = 'empty'; // create an empty layout in app/views/layouts/empty.ctp              }        }  Add header code in empty layout <?php header('Content-type: text/xml');?> <?php echo $this->Xml->header(); ?> <?php echo $content_for_layout; ?> Step-4 Set up View To generate XML Create xml folder inside Posts vi...

Simple JavaScript Object and Class Examples

In JavaScript, most things are objects. An object is a collection of related data and/or functionality Namespace: Everything you create in JavaScript is by default global. In JavaScript namespace is Global object . How to create a namespace in JavaScript? Create one global object, and all variables, methods, and functions become properties of that object. Example:  // global namespace var MYAPP = MYAPP || {}; Explaination: Here we first checked whether MYAPP is already defined.If yes, then use the existing MYAPP global object, otherwise create an empty object called MYAPP How to create sub namespaces? // sub namespace MYAPP.event = {}; Class JavaScript is a prototype-based language and contains no class statement.JavaScript classes create simple objects and deal with inheritance. Example: var Person = function () {}; Explaination: Here we define a new class called Person with an empty constructor. Use the class keyword class Calculation {}; A class expr...

How to Add Next Previous links to The Event Calendar

Add Next/Previous links to The Event Calendar Wordpress Plugin Add code to your child theme’s functions.php file /**  * Allows visitors to page forward/backwards in any direction within month view */ if ( class_exists( 'Tribe__Events__Main' ) ) { class ContinualMonthViewPagination {     public function __construct() {         add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) );         add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) );     }     public function next_month() {         $url = tribe_get_next_month_link();         $text = tribe_get_next_month_text();         $date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() );         return '<a data-month="' . $date . '" href="' . $url . '" rel="next"...