How change standard decoration in zend form - zend-framework

in my Directory Form i have FormArena
$this->addElement('radio', 'warrior',array(
'decorators' => array(
'ViewHelper',
),
'disableLoadDefaultDecorators' => true,
'separator' => '',
));
On my view page i have
<?php echo $this->forms['formarena']->getItem('warrior'); ?>
And in controller i have
$getWarriorsList = $this->objArena->getActiveUsers($this->varUserData['id']);
$objFormArena = new FormArena();
if (!empty($getWarriorsList)){
foreach($getWarriorsList AS $varWarriors)
$varOptions[$varWarriors['id_users']] = $varWarriors['nick'];
$objFormArena->warrior->addMultiOptions($varOptions);
unset($varOptions);
}
$this->view->forms = array(
'formarena' => $objFormArena,
);
Ok so it is easy. I take data from base and add option to view by controller. But when i see source code on page i have:
<div class="radio">
<label for="warrior-27">
<input type="radio" name="warrior" id="warrior-27" value="27">makapaka</label>
<label for="warrior-29">
<input type="radio" name="warrior" id="warrior-29" value="29">Kasia</label>
</div>
but i need do
<div class="radio">
<input id="warrior-27" type="radio" name="warrior" value="27">
<label for="warrior-27">makapaka</label>
<input id="warrior-29" type="radio" name="warrior" value="29">
<label for="warrior-29">Kasia</label>
</div>
What should i need to do. I tried search from web but i have still nothing from 2 days :(

The current option does not allow rendering in the exact format you wished.
It can only be either
<div class="radio">
<label for="warrior-27">
<input type="radio" name="warrior" id="warrior-27" value="27">makapaka</label>
<label for="warrior-29">
<input type="radio" name="warrior" id="warrior-29" value="29">Kasia</label>
</div>
or
<div class="radio">
<label for="warrior-27">
makapaka
<input type="radio" name="warrior" id="warrior-27" value="27"></label>
<label for="warrior-29">
Kasia
<input type="radio" name="warrior" id="warrior-29" value="29"></label>
</div>
To render your form element as you mentioned, you need to create either a custom view helper and pass it as an option to the ViewHelper decorator or use the ViewScript decorator to generate a custom output.
Personally, I would prefer the ViewScript decorator for its easy of use.
Example of use :
$this->addElement('radio', 'warrior',array(
'decorators' => array(
array('ViewScript', array('viewScript' => 'decorator.phtml'))
)
));
and in your decorator.phtml
<div class="radio">
<?php foreach($this->element->getMultiOptions() as $value => $label): ?>
<input id="<?php echo $this->element->getName() ?>-<?php echo $value ?>" type="radio" name="<?php echo $this->element->getName() ?>" value="<?php echo $value ?>">
<label for="<?php echo $this->element->getName() ?>-<?php echo $value ?>"><?php echo $label ?></label>
<?php endforeach ?>
</div>
NB : This script file can be used for all your form radio elements
Hope it helps

Related

update in codeigniter 3, it's run but database didnt changed

i dont understand with my code. it's run, and work. but when i see in database didnt changed.
here's my controller, function perbarui for get id data, get the data id from model (MMobil).
public function perbarui($id = NULL){
$this->load->model('merek');
$this->load->library('form_validation');
$data['merk'] = $this->merek->getList();
$data['detail'] = $this->MMobil->detail($id);
$submit = $this->input->post('submit');
print_r($data);
if ($submit) {
$nomor_kendaraan = $this->input->post('nomor_kendaraan');
$nomor_mesin = $this->input->post('nomor_mesin');
$id_merek = $this->input->post('id_merek');
$tahun_beli = $this->input->post('tahun_beli');
$nama_mobil = $this->input->post('nama_mobil');
$this->form_validation->set_rules('nama_mobil', 'Nama_Mobil', 'required');
$this->form_validation->set_rules('nomor_kendaraan', 'Nomor_Kendaraan', 'required');
$data['detik'] = $this->MMobil->setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil);
if ($this->form_validation->run() == FALSE) {
$data['errors'] = TRUE;
}else{
$data['detail'] = $this->MMobil->detail($id);
print_r($data);
}
//redirect('Master');
}
$this->load->view('master-detail-mobil', $data);
}
here's my models. function setData for storage variable after click submit. function edit get id data and get variable arrayData from function setData
public function setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil){
$this->nomor_kendaraan = $nomor_kendaraan;
$this->nomor_mesin = $nomor_mesin;
$this->id_merek = $id_merek;
$this->tahun_beli = $tahun_beli;
$this->nama_mobil = $nama_mobil;
}
public function edit($id){
$arrayData = array(
'nomor_kendaraan' => $this->nomor_kendaraan,
'nomor_mesin' => $this->nomor_mesin,
'id_merek' => $this->id_merek,
'tahun_beli' => $this->tahun_beli,
'nama_mobil' => $this->nama_mobil,
);
$this->db->where('nomor_mesin', $id);
return $this->db->update($this->table,$arrayData);
}
here's my views
<?php $this->load->view('header.php'); ?>
<?php
echo"<h4>UPDATE DATA</h4>";
?>
<form class="form-horizontal" role="form" method="post" action="<?php echo site_url()?>/Master/perbarui/">
<div class="form-group">
<label class="control-label col-sm-2" for="noken">Nomor Kendaraan :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_kendaraan" value="<?php
echo #$detail->nomor_kendaraan;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes">Nomor Mesin :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_mesin" value="<?php
echo #$detail->nomor_mesin;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="merk">Merek Mobil :</label>
<div class="col-sm-10">
<select class="form-control" name="id_merek">
<?php foreach ($merk as $mrk) :?>
<option value="<?php echo $mrk->id_merek ?>">
<?php
echo $mrk->nama_merek;
?>
</option>
<?php endforeach?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="thn">Tahun Beli :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="tahun_beli" value="<?php
echo #$detail->tahun_beli; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="namo">Nama Mobil :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nama_mobil" value="<?php
echo #$detail->nama_mobil; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes"></label>
<div class="col-sm-2">
<input type="submit" class="form-control" name="submit" value="simpan">
</div>
</div>
</form>
<?php $this->load->view('footer.php'); ?>
and here my pictures before click submit and after click submit. i typed print_r for see the data array. if you see data array detail before click submit, there is data in detail. but after click submit data array detail gone.
enter image description here enter image description here

cakephp2 override Form input action

default cakephp echo $this->Form->input('name');
returns something like this
<div>
<label for="mdl.name">name</label>
<input type="text" id="mdl.name" name="mdl.name" />
</div>
but I want different let's say I want the the following
<div class="form-group more classes">
<h3>name</h3>
<div>
<span class="extra span"></span>
<input type="text" class="form-control" id="mdl.name">
<span class="extra span"></span>
</div>
<label for="mdl.name">name</label>
<span class="another span"></span>
</div>
I saw /lib/cake/view/Helper/FormHelper.php copied to app/view/Helper
but have not seen any div, label or input tags
What you might be looking for is:
echo $this->Form->input('field', array(
'before' => '--before--',
'after' => '--after--',
'between' => '--between---'
));
Which will output:
<div class="input">
--before--
<label for="UserField">Field</label>
--between---
<input name="data[User][field]" type="text" value="" id="UserField" />
--after--
</div>
Reference: CakePHP 2.x FormHelper

How to Modify Active Form Field in yii2

Normally, this code <?= $form->field($model, 'q_36a')->checkbox() ?> will produce the following...
<div class="form-group field-tblquestion-q_36a required">
<input type="hidden" name="TblQuestion[q_36a]" value="0"><label><input type="checkbox" id="tblquestion-q_36a" name="TblQuestion[q_36a]" value="1"> Q 36a</label>
<div class="help-block"></div>
</div>
how do i modify it to make it like this?
<label>
<input name="switch-field-1" class="ace ace-switch ace-switch-5" type="checkbox">
<span class="lbl"></span>
</label>
I want to make it like this because I integrated ace admin template in my app.
Got it working.
<?= $form->field($model, 'q_36a', ['template' => "{input}<span class='lbl'></span>",])->checkbox(['class' => 'ace ace-switch ace-switch-5'], false) ?>

mark the input box red if the required field of a form is not filled

i'm using Codeigniter. i have a form which takes information about users. What i want to do is to check whether all the required fields are filled up or not.If any of the required fields is not filled up i want mark that input box red. Right now my codes only check if the required fields are filled up or not. if not it says the "field is required" but how to mark input box.I'm a bit confused how to do this thing.Can somebody help me out with a little hint. Thanks.
the view for my form:
<?php
$attributes = array('class' => '', 'id' => '');
echo form_open('register', $attributes); ?>
<p>
<label for="name">Name <span class="required">*</span></label>
<?php echo form_error('name'); ?>
<br /><input id="name" type="text" name="name" value="<?php
echo set_value('name'); ?>"
</p>
<p>
<label for="username">Username <span class="required">*</span></label>
<?php echo form_error('username'); ?>
<br /><input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>"
</p>
<p>
<label for="password">Password <span class="required">*</span></label>
<?php echo form_error('password'); ?>
<br /><input id="password" type="password" name="password" value="<?php echo set_value('password'); ?>"
</p>
<p>
<label for="email">Email <span class="required">*</span></label>
<?php echo form_error('email'); ?>
<br /><input id="email" type="text" name="email" value="<?php echo set_value('email'); ?>"
</p>
<p>
<label for="phone">Phone</label>
<?php echo form_error('phone'); ?>
<br /><input id="phone" type="text" name="phone" value="<?php echo set_value('phone'); ?>"
</p>
</p>
<p>
<input type="submit" value="Submit information" class="formbutton"/>
</p>
<?php echo form_close(); ?>
Generally, I'd recommend creating an textInputError class where you adjust the input style, and then apply it based on the existence of the error...
class="<?php echo (form_error('username') ? 'textInputError' : '') ?>"
in place in the input element...
<input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>" class="<?php echo (form_error('username') ? 'textInputError' : '') ?>">

Codeigniter Form Helper Duplicate from_hidden?

Im totally stumped.. Im creating some form elements using the CI form helper and for some weird reason, its creating a duplicate version.
Here is my PHP
<div id="receiveInventoryItemDetails">
<p><?php echo form_open('#', array("class" => "nyroModal form label-inline"));?></p>
<?php echo form_hidden('item_id', '', "readonly = true"); ?>
<?php echo form_hidden('purchase_order_id', '', "readonly = true"); ?>
<p><?php echo form_label('Item Name', 'item_name');?><?php echo form_input('item_name', '', "readonly = true"); ?></p>
<p><?php echo form_label('Item QTY', 'item_qty');?><?php echo form_input('item_qty', ''); ?></p>
<?php echo form_close();?>
</div>
<div class="buttonrow">
<button class="btn-sec" onclick="inventoryC.receiveSubmitItem();"><span>Add To Inventory</span></button>
</div>
Here is the HTML output
<div id="receiveInventoryItemDetails">
<p><form action="https://mysite.com/#.abl" method="post" accept-charset="utf-8" class="nyroModal form label-inline"></p>
<input type="hidden" name="item_id" value="" />
<input type="hidden" name="item_id" value="" />
<input type="hidden" name="purchase_order_id" value="" />
<p><label for="item_name">Item Name</label><input type="text" name="item_name" value="" readonly = true /></p>
<p><label for="item_qty">Item QTY</label><input type="text" name="item_qty" value="" /></p>
</form>
</div>
<div class="buttonrow">
<button class="btn-sec" onclick="inventoryC.receiveSubmitItem();"><span>Add To Inventory</span></button>
</div>
You can't use html attributes via third parameter. Look at form helper source code
This should be work:
<?php echo form_hidden('item_id', ''); ?>