I am learning Zend by following Getting Started with Zend Framework 2 tutorial but I am facing a prolem with the form layout, it's broken:
How do I fix this issue to make it likes the form in the tutorial:
AlbumForm code:
public function __construct($name = null)
{
// we want to ignore the name passed
parent::__construct('album');
$this->add(array(
'name' => 'id',
'type' => 'Hidden',
));
$this->add(array(
'name' => 'title',
'type' => 'Text',
'options' => array(
'label' => 'Title',
),
));
$this->add(array(
'name' => 'artist',
'type' => 'Text',
'options' => array(
'label' => 'Artist',
),
));
$this->add(array(
'name' => 'submit',
'type' => 'Submit',
'attributes' => array(
'value' => 'Go',
'id' => 'submitbutton',
),
));
}
and the view code:
<?php
// module/Album/view/album/album/add.phtml:
$title = 'Add new album';
$this->headTitle($title);
?>
<h1><?php echo $this->escapeHtml($title); ?></h1>
<?php
$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('artist'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
Zend Framework has possibility to change style in elements. to add "clear:both;" style I think will solve problem?
<div class="form_element">
<?php
$artist = $form->get('artist');
echo $this->formRow($artist);
?></div>
<div style="clear:left;"></div>
<div class="form_element">
<?php
$title = $form->get('title');
echo $this->formRow($title);
?></div>
echo '<div style="clear:both;"> </div>';
echo $this->formRow($form->get('title'));
echo '<div style="clear:both;"> </div>';
echo $this->formRow($form->get('artist'));
echo '<div style="clear:both;"> </div>';
echo $this->formSubmit($form->get('submit'));
echo '<div style="clear:both;"> </div>';
The easiest and fastest way is to add this css..
form label
{
display: block;
}
Note that it will be slightly different from the tutorial.
Related
I got stuck in a a problem in which I need to update some info from database in the same page that is shown.
On this case I'm fetching some "global settings" from a website in an index page which comes with a form in it. Here is a picture of it just to make it more clear to understand what I mean.
As you can see I created the button and I made it possible to see the values from the database, the problem is that I can not figure it out how to update it from there. Can somebody suggest an idea?
Here is my controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Settings extends Admin_Controller {
public function index()
{
$this->form_validation->set_rules('website_favicon', 'Favicon', 'trim|required|min_length[4]');
$this->form_validation->set_rules('website_logo', 'Logon', 'trim|required|min_length[4]');
$this->form_validation->set_rules('website_name', 'Website Name', 'trim|required|min_length[4]');
$this->form_validation->set_rules('website_credits', 'Credits', 'trim|required|min_length[4]');
$this->form_validation->set_rules('website_credits_link', 'Credits Link', 'trim|required|min_length[4]');
$this->form_validation->set_rules('website_copyright', 'Copyright', 'trim|required|min_length[4]');
if($this->form_validation->run() == FALSE){
// Get Current Subject
$data['item'] = $this->Settings_model->get_website_data();
//Load View Into Template
$this->template->load('admin', 'default', 'settings/index', $data);
} else {
// Create website settings
$data = array(
'website_favicon' => $this->input->post('website_favicon'),
'website_logo' => $this->input->post('website_logo'),
'website_name' => $this->input->post('webiste_name'),
'website_credits' => $this->input->post('website_credits'),
'website_credits_link' => $this->input->post('website_credits_link'),
'website_copyright' => $this->input->post('website_copyright'),
);
// Update User
$this->Settings_model->update($id, $data);
// Activity Array
$data = array(
'resource_id' => $this->db->insert_id(),
'type' => 'website settings',
'action' => 'updated',
'user_id' => $this->session->userdata('user_id'),
'message' => 'User (' . $data["username"] . ') updated the website settings'
);
// Add Activity
$this->Activity_model->add($data);
//Create Message
$this->session->set_flashdata('success', 'Website setting has been updated');
//Redirect to Users
redirect('admin/settings');
}
}
}
Here is my model:
<?php
class Settings_model extends CI_MODEL
{
function __construct()
{
parent::__construct();
$this->table = 'website_settings';
}
public function update($id, $data)
{
$this->db->where('id', $id);
$this->db->update($this->table, $data);
}
public function get_website_data()
{
$this->db->select('*');
$this->db->from($this->table);
$this->db->where('id', 1);
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->row();
} else {
return false;
}
}
}
and here is my view(index.php) with the form:
<h2 class="page-header">Website Settings</h2>
<?php if($this->session->flashdata('success')) : ?>
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
<?php echo $this->session->flashdata('success') ?></div>
<?php endif; ?>
<?php if($this->session->flashdata('error')) : ?>
<div class="alert alert-danger alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
<?php echo $this->session->flashdata('error') ?></div>
<?php endif; ?>
<?php echo validation_errors('<p class="alert alert-danger">'); ?>
<?php echo form_open('admin/settings/index/'.$item->id); ?>
<!-- Website Favicon -->
<div class="form-group">
<?php echo form_label('Website Favicon', 'title'); ?>
<?php
$data = array(
'name' => 'website_favicon',
'id' => 'website_favicon',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_favicon
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website Logo -->
<div class="form-group">
<?php echo form_label('Website Logo', 'website_logo'); ?>
<?php
$data = array(
'name' => 'website_logo',
'id' => 'website_logo',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_logo
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website Name -->
<div class="form-group">
<?php echo form_label('Website Name', 'website_name'); ?>
<?php
$data = array(
'name' => 'website_name',
'id' => 'website_name',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_name
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website Credits -->
<div class="form-group">
<?php echo form_label('Website Credits to', 'website_credits'); ?>
<?php
$data = array(
'name' => 'website_credits',
'id' => 'website_credits',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_credits
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website Credits Link -->
<div class="form-group">
<?php echo form_label('Website Credits to Link', 'website_credits_link'); ?>
<?php
$data = array(
'name' => 'website_credits_link',
'id' => 'website_credits_link',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_credits_link
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website Copyright -->
<div class="form-group">
<?php echo form_label('Copyrights', 'website_copyright'); ?>
<?php
$data = array(
'name' => 'website_copyright',
'id' => 'website_copyright',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_copyright
);
?>
<?php echo form_input($data); ?>
</div>
<!-- Website First Ad -->
<div class="form-group">
<?php echo form_label('Ad One', 'website_first_ad'); ?>
<?php
$data = array(
'name' => 'website_first_ad',
'id' => 'website_first_ad',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_first_ad
);
?>
<?php echo form_textarea($data); ?>
</div>
<!-- Website Second Ad -->
<div class="form-group">
<?php echo form_label('Ad Two', 'website_second_ad'); ?>
<?php
$data = array(
'name' => 'website_second_ad',
'id' => 'website_second_ad',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_second_ad
);
?>
<?php echo form_textarea($data); ?>
</div>
<!-- Website Third Ad -->
<div class="form-group">
<?php echo form_label('Ad Three', 'website_third_ad'); ?>
<?php
$data = array(
'name' => 'website_third_ad',
'id' => 'website_third_ad',
'maxlength' => '100',
'class' => 'form-control',
'value' => $item->website_third_ad
);
?>
<?php echo form_textarea($data); ?>
</div>
<?php echo form_submit('mysubmit', 'Update Website', array('class' => 'btn btn-primary')); ?>
<?php echo form_close(); ?>
Thanks for helping.
Check if the data is posted thru the controller. then use set_value to your input fields to retain the values after submit
CONTROLLER
public function index(){
if($this->input->post()){
//set rules for form validation
if($this->form_validation->run() !== FALSE){
//then update
}
}
//your views, data or any other things you do
}
VIEW
echo form_input('name', set_value('name'));
On click of the button you can bind the ajax call to submit the data to the update action of the controller and you can handle response to show relevant message on the same page.
Sample ajax call
$.ajax({
url:'settings/update',//controller action
type:'POST',
dataType:'JSON',
data:{'data':data,'id':id},//form data you need to upate with the id
success:function(response) {
//show success message here
},
error:function(response) {
//show error message here
}
});
Hope this helps.
I am using Cakephp2.0
I have a table for all my images and a table for features.
I have a form that takes the following inputs:
name of feature
text and multiple images with image name.
I need to insert the feature name and text into the feature table, grab id just created, and insert it along with all the image info from the form. I am not sure how to make the controller do that.
controller:
public function add() {
if ($this->request->is('post')) {
$this->Feature->create();
if ($this->Feature->saveAll($this->request->data)) {
$this->Session->setFlash(__('Your Feature has been saved.'));
return $this->redirect(array('controller' => 'dashbords', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your Feature.'));
}
}
form:
<?php
echo $this->Form->create('Feature', array(
'class' => 'form-horizontal',
'role' => 'form',
'type' => 'file',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'class' => array('form-control'),
'label' => array('class' => 'col-lg-2 control-label'),
'between' => '<div class="col-lg-6">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
))); ?>
<?php
echo '<fieldset>';
echo '<legend>Add Features</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input('Feature.name', array('class' => 'feature'));
echo '</div>';
echo '<div class="col-md-8">';
echo '';
echo '</div></div>';
echo '</fieldset>';
//----------------------- Image Block -----------------------------//
// group main image //
echo '<fieldset>';
echo '<div class="row"><div class="col-md-4">';
echo '<legend>Main Image</legend>';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'main_image'));
echo $this->Form->input('Image.name', array(
'class' => 'main_image'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '1',
'class' => 'main_image'));
echo '</div>';
// bottom left image //
echo '<div class="col-md-4">';
echo '<legend>Bottom Left</legend>';
// group image 2//
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'bl'));
echo $this->Form->input('Image.name', array(
'class' => 'bl'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '2',
'class' => 'bl'));
echo '</div>';
// bottom right //
echo '<div class="col-md-4">';
echo '<legend>Bottom Right</legend>';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'br'));
echo $this->Form->input('Image.name', array(
'class' => 'br'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '3',
'class' => 'br'));
echo '</div></div>';
echo '</fieldset>';
//----------------------- Gallery Block -----------------------------//
// group 1
echo '<fieldset>';
echo '<legend>Gallery</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'gallery1'));
echo $this->Form->input('Image.name', array(
'class' => 'gallery1'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class' => 'gallery1'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 2//
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' =>'gallery2'));
echo $this->Form->input('Image.name', array('class'=>'gallery2'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery2'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 3 //
echo $this->Form->input(
'upload', array(
'type' => 'file',
'class' => 'gallery3'));
echo $this->Form->input('Image.name', array('class'=> 'gallery3'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery3'));
echo '</div></div>';
// Feature Text //
echo '</fieldset>';
echo '<div class="row"><div class="col-md-12"><fieldset>';
echo '<legend>Content</legend>';
echo $this->Form->textarea('Feature.content', array('rows' => '10', 'cols' => '75'));
echo '</fieldset></div></div>';
?>
</fieldset>
<div class="row">
<div class="col-md-2 col-md-offset-10">
<?php echo $this->Form->end('Save Content'); ?>
</div>
</div>
Modles:
Featuer:
class Feature extends AppModel{
public $useTable = "features";
public $displayField = "name";
public $hasMany = array(
'Image'=>array('classname' => 'Image', 'foreignkey' => 'image_id'),
);
}
Update:
Per #SverriM.Olsen I have done some more research. I have concluded a few things like how to upload multiple images. Which then lead me to the fact I did dont know how to allow for a name to use as the image alt tag, so I removed that and in my controller add function I looped through the array and grabbed the file name minus the extension. I have read about set and saveAssociated. Where I am at now it how to join the newly created array of names and add then to the image table with the images from the form. here is an updated controller:
public function add() {
//get array of images loop throug
$file = $this->request->data['Image']['image'];
// get file name and extract name - extention
$name = array();
foreach($file as $key=>$value){
foreach($value as $k=>$v){
if($k == 'name'){
$file = $v;
$info = pathinfo($file);
$file_name = basename($file,'.'.$info['extension']);
$this->set(
'Image', array(
'name'=> $name[] = $file_name));
}
}
}
if ($this->request->is('post')) {
$this->Feature->create();
if ($this->Feature->saveAssociated($this->request->data)) {
$this->Session->setFlash(__('Your Feature has been saved.'));
return $this->redirect(array('controller' => 'dashbords', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to add your Feature.'));
debug($this->Feature->validationErrors);
}
}
and an updated form (add.ctp)
<?php
echo $this->Form->create('Feature', array(
'class' => 'form-horizontal',
'role' => 'form',
'type' => 'file',
'inputDefaults' => array(
'format' => array('before', 'label', 'between', 'input', 'error', 'after'),
'div' => array('class' => 'form-group'),
'class' => array('form-control'),
'label' => array('class' => 'col-lg-2 control-label'),
'between' => '<div class="col-lg-6">',
'after' => '</div>',
'error' => array('attributes' => array('wrap' => 'span', 'class' => 'help-inline')),
))); ?>
<?php
echo '<fieldset>';
echo '<legend>Add Features</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input('name');
echo $this->Form->textarea('content', array('rows' => '5', 'cols' => '55'));
echo '<br/><br/>';
echo '<div class="col-md-8">';
echo '';
echo '</div></div>';
echo '</fieldset>';
//----------------------- Image Block -----------------------------//
// group main image //
echo '<fieldset>';
echo '<div class="row"><div class="col-md-4">';
echo '<legend>Main Image</legend>';
echo '<p>Uploade multiple image for each lug set at once.</p>';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'multiple' => 'multiple',
'class' =>'main_image'));
echo $this->Form->input('Image.name', array(
'type' => 'hidden',
'class' => 'main_image'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '1',
'class' => 'main_image'));
echo '</div>';
// bottom left image //
echo '<div class="col-md-4">';
echo '<legend>Bottom Left</legend>';
// group image 2//
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'multiple' => 'multiple',
'class' =>'bl'));
echo $this->Form->input('Image.name', array(
'class' => 'bl'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '2',
'class' => 'bl'));
echo '</div>';
// bottom right //
echo '<div class="col-md-4">';
echo '<legend>Bottom Right</legend>';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'class' =>'br'));
echo $this->Form->input('Image.name', array(
'class' => 'br'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '3',
'class' => 'br'));
echo '</div></div>';
echo '</fieldset>';
//----------------------- Gallery Block -----------------------------//
// group 1
echo '<fieldset>';
echo '<legend>Gallery</legend>';
echo '<div class="row"><div class="col-md-4">';
echo $this->Form->input(
'Image.image.', array(
'type' => 'file',
'class' =>'gallery1'));
echo $this->Form->input('Image.name', array(
'class' => 'gallery1'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class' => 'gallery1'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 2//
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'class' =>'gallery2'));
echo $this->Form->input('Image.name', array('class'=>'gallery2'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery2'));
echo '</div>';
echo '<div class="col-md-4">';
// group image 3 //
echo $this->Form->input(
'Image.image.', array(
'type' => 'file.',
'class' => 'gallery3'));
echo $this->Form->input('placement_id', array(
'type' => 'hidden',
'value' => '4',
'class', 'gallery3'));
echo '</div></div>';
?>
</fieldset>
<div class="row">
<div class="col-md-2 col-md-offset-10">
<?php echo $this->Form->end('Save Content'); ?>
</div>
</div>
Any help or pointer to places that will help is great. I will try some more googling.
Thank you in advance.
I created a simple form in typical ZF2 application. The form class code is just a modified code provided by Zend's Album example.
<?php
namespace Admin\Form;
use Zend\Form\Form;
class CityForm extends Form
{
public function __construct($name = null)
{
parent::__construct('city');
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text'
),
'options' => array(
'label' => 'Name',
),
));
$this->add(array(
'name' => 'province',
'attributes' => array(
'type' => 'text'
),
'options' => array(
'label' => 'Province',
),
));
$this->add(array(
'name' => 'country',
'attributes' => array(
'type' => 'text'
),
'options' => array(
'label' => 'Country',
),
));
$this->add(array(
'name' => 'coordinate',
'attributes' => array(
'type' => 'text'
),
'options' => array(
'label' => 'Coordinate',
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Save',
'id' => 'submitButton',
),
));
}
}
And call it like this in CityController, a typical controller extends AbstractActionController:
public function addAction()
{
$form = new CityForm();
$viewData = array(
'form' => $form
);
return new ViewModel($viewData);
}
Finally in view I echo it like this:
<?php $title = 'Add New City'; ?>
<?php $this->headtitle($title); ?>
<h1><?php echo $this->escapehtml($title); ?></h1>
<?php $form = $this->form; ?>
<?php $form->setAttribute('action', $this->url('city', array('action' => 'add'))); ?>
<?php $form->prepare(); ?>
<?php
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('province'));
echo $this->formRow($form->get('country'));
echo $this->formRow($form->get('coordinate'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
What I expected to see is a vertical form like this:
But what i got is an ugly form like this:
What's wrong with my code? Please help.
EDIT:
When I inspect element, the form generated is strange. The <input> element is inside the <label> element.
<form id="city" name="city" method="post" action="/karciscus/public/admin/city/add">
<input type="hidden" value="" name="id">
<label>
<span>Name</span><input type="text" value="" name="name">
</label>
<label>
<span>Province</span><input type="text" value="" name="province">
</label>
<label>
<span>Country</span><input type="text" value="" name="country">
</label>
<label>
<span>
Coordinate</span><input type="text" value="" name="coordinate">
</label>
<input type="submit" value="Save" id="submitButton" name="submit">
</form>
I'm pretty sure it is the cause of my ugly rendered form. I think it is not supposedly like that. How to fix it?
That's something you have to do in your css.
Give your label a fixed width/length will align them correctly.
If you want to achieve your example above, add display:block for labels then they will each take a full line, like a block element.
Fixed. For other who has the same experience with me, just add element id in form class:
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
'id' => 'name', // Must have id, will render strange otherwise!
),
'options' => array(
'label' => 'Name',
),
));
This fixes the issue for me.
Use the built in twitter bootstrap css which comes with Zf2. Use divs to render your form elements. I understand that everyone thinks about the form data that you set on your .html is pure php data and you cant align it.
<div class="row">
<?php $title = 'Add New City'; ?>
<div>
<div class="row">
<?php $this->headtitle($title); ?>
<h1><?php echo $this->escapehtml($title); ?></h1>
<?php $form = $this->form; ?>
<?php $form->setAttribute('action', $this->url('city', array('action' => 'add'))); ?>
<?php $form->prepare(); ?>
<?php
echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('name'));
echo $this->formRow($form->get('province'));
echo $this->formRow($form->get('country'));
echo $this->formRow($form->get('coordinate'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
?>
</div>
Thats the sample....try doing what you like just like what i have shown above and you are good to go.
I'm using the following code to generate a form.
echo $this->Form->create('External');
echo $this->Form->input('program_title', array('label' => 'Program Name'));
echo $this->Form->input('reference_code', array('label' => 'Reference No.'));
echo $this->Form->input('date_received', array('label' => 'Date Received', 'type' => 'date'));
echo $this->Form->input('date_released', array('value' => date('Y-m-d'), 'type' => 'hidden'));
echo $this->Form->input('inclusive_date_start', array('label' => 'Inclusive Date Start', 'type' => 'date'));
echo $this->Form->input('inclusive_date_end', array('label' => 'Inclusive Date End', 'type' => 'date'));
echo $this->Form->input('time_start', array('label' => 'Time Start', 'type' => 'time'));
echo $this->Form->input('time_end', array('label' => 'Time End', 'type' => 'time'));
echo $this->Form->end('Add Program');
And it creates the following:
How do I make it show up like this one instead?
The second image was just edited so I can show you how I want it to look like. Care to shed some light?
Within CakePHP, you don't always have to include a label for your form elements, allowing you to do custom groupings and positions.
Here is a quick example of how you can do it with your code. For simplicity, I kept everything inside of PHP, but you can break out of PHP and write the actual HTML as well. Please note the use of 'label' => false
echo $this->Form->create('External');
echo $this->Form->input('program_title', array('label' => 'Program Name'));
echo $this->Form->input('reference_code', array('label' => 'Reference No.'));
echo $this->Form->input('date_received', array('label' => 'Date Received', 'type' => 'date'));
echo $this->Form->input('date_released', array('value' => date('Y-m-d'), 'type' => 'hidden'));
//Custom HTML code
echo '<div>Inclusive Date</div>';
echo '<div>';
echo '<div style="float: left;">
echo $this->Form->input('inclusive_date_start', array('label' => false, 'type' => 'date'));
echo '</div>';
echo '<div style="float: left;">-</div>';
echo '<div style="float: left;">';
echo $this->Form->input('inclusive_date_end', array('label' => false, 'type' => 'date'));
echo '</div>'
echo '<div style="clear: both;"></div>';
echo '</div>';
//Back to normal PHP
echo $this->Form->input('time_start', array('label' => 'Time Start', 'type' => 'time'));
echo $this->Form->input('time_end', array('label' => 'Time End', 'type' => 'time'));
echo $this->Form->end('Add Program');
i am very much new to cakephp. I have created a simple form with input controls on it as follows:
<?php
echo $this->Form->create();
echo $this->Form->input('name');
echo $this->Form->input('address', array('rows' => '3'));
echo $this->Form->input('aaa', array(
'type' => 'date',
'label' => 'select',
'before' => '--before--',
'after' => '--after--',
'between' => 'Date',
'separator' => '****',
'empty' => '--select--'
));
echo $this->Form->checkbox('subjects', array('value' => 'Java'));
?>
java
<?php
echo $this->Form->input('gen', array(
'type' => 'radio',
'options' => array('m', 'f')
));
echo $this->Form->input('file', array('type' => 'file'));
echo $this->Form->input('listbox', array('options' => array(1,2,3,4,5), 'multiple' => 'multiple'));
echo $this->Form->end('Submit');
?>
i wish to print the values entered in these components on another page. how do i do that?
i tried to do it with the help of session(which seems to be inappropriate) as follows:
public function contactus() {
if ($this->request->data!=null) {
$var=$this->request->data;
$this -> Session -> write('myvar', $this->request->data);
//$this->set($var, $this->request->data);
$this->redirect(array('action' => 'contactview'));
}
}
but it outputs array and i cant use session to store each component's value.
how do i solve this?
According to cakephp book (Form: http://book.cakephp.org/1.3/view/1384/Creating-Forms)
<?php
echo $this->Form->create(null,
array('url' => array('controller' => 'recipes', 'action' => 'add')));
?>
//Output:
<form method="post" action="/recipes/add">
Therefore , just change your create function and add the url option.
Rather than using the session, I used this->data and it was able to resolve my problem.