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...

How To Create Shortcodes In WordPress

We can create own shortcode by using its predified hooks add_shortcode( 'hello-world', 'techsudhir_hello_world_shortcode' ); 1. Write the Shortcode Function Write a function with a unique name, which will execute the code you’d like the shortcode to trigger: function techsudhir_hello_world_shortcode() {    return 'Hello world!'; } Example: [hello-world] If we were to use this function normally, it would return Hello world! as a string 2. Shortcode function with parameters function techsudhir_hello_world_shortcode( $atts ) {    $a = shortcode_atts( array(       'name' => 'world'    ), $atts );    return 'Hello ' . $a['name'] . !'; } Example: [hello-world name="Sudhir"] You can also call shortcode function in PHP using do_shortcode function Example: do_shortcode('[hello-world]');

How to replace plain URLs with links

Here we will explain how to replace Urls with links from string Using PHP $string ='Rajiv Uttamchandani is an astrophysicist, human rights activist, and entrepreneur. Academy, a nonprofit organization dedicated to providing a robust technology-centered education program for refugee and displaced youth around the world.  CNN Interview - https://www.youtube.com/watch?v=EtTwGke6Jtg   CNN Interview - https://www.youtube.com/watch?v=g7pRTAppsCc&feature=youtu.be'; $string = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.%-=#]*(\?\S+)?)?)?)@', '<a href="$1">$1</a>', $string); Using Javascript <script> function linkify(inputText) {     var replacedText, replacePattern1, replacePattern2, replacePattern3;     //URLs starting with http://, https://, or ftp://     replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;     replacedText = inputT...