I am using the CakePHP-AjaxMultiUpload Plugin, and have following code inside edit.ctp but the drop box is not visible here.
<div class="useTypes form">
<?php echo $this->Form->create('UseType'); ?>
<fieldset>
<legend><?php echo __('Edit Use Type'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
echo $this->Form->input('description');
echo $this->Upload->edit('UseType', $this->Form->fields['UseType.id']);
?>
</fieldset>
<?php
echo $this->Form->end(__('Submit')); ?>
</div>
but when I use the following code alone , it is visible
<?php echo $this->Upload->edit('UseType', $this->Form->fields['UseType.id']);?>
I tried this in cakephp 2.6 with default theme.
You are not supposed to wrap $this->Upload->edit() inside a <form> tag, as it already creates its own form.
You might also need to replace:
$this->Form->fields['UseType.id']
with:
$this->Form->value('UseType.id')
In summary, this should work:
<?php echo $this->Form->create('UseType'); ?>
<fieldset>
<legend><?php echo __('Edit Use Type'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
echo $this->Form->input('description');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
<?php echo $this->Upload->edit('UseType', $this->Form->value('UseType.id'));?>
Edit
If you need to upload files on your /use_types/add view, you can do the following.
In UseTypeController::add() include:
$this->set('id',CakeText::uuid()); //String::uuid() for CakePHP 2.6 or lower
and in /app/View/UseTypes/add.ctp:
<?php echo $this->Form->input('id',array('type' => 'hidden', 'value' => $id)); ?>
The drawback is that if you fail to save your model after uploading files via AJAX, these will be left orphaned.
Related
How can i add more tabs and fields to a joomla component in backend,
-Tried editing the view xml file adding more fieldsets, no success
-Tried editing the edit file in view admin component, no success,
In other words i want to achieve this, just like the image
Any help?
You have to set it to the view template admin\views\*view_name\tmpl\*template_name.php.
The structure that you have to use is:
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_COMPONENT_NAME_TAB_1_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'advanced', JText::_('COM_COMPONENT_NAME_TAB_2_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
You could also check core components to get more examples.
As for the contents of each tab, you could restrict the loop to get the fields of one fieldset only using:
<?php foreach ($this->form->getFieldset("general") as $field): ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>
I have a form like this as yii active record :
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'arsip-perihal-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'nama_arsip'); ?>
<?php echo $form->textField($model,'nama_arsip',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'nama_arsip'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'kode_primary'); ?>
<?php echo $form->textField($model,'kode_primary',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'kode_primary'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'Keterangan'); ?>
<?php echo $form->textField($model,'Keterangan'); ?>
<?php echo $form->error($model,'Keterangan'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Can I use a HTML tag, An example textbox
First name: <input type="text" name="fname"><br>
if it can, how to use it? how to set default from $model like the form above?
Thank You,
When you use $form->textField, CActiveForm generates a textbox with ModelName[attributeName] name. So you can provide name for your textbox with this structure.
<input type="text" name="ModelName[fname]">
Note, "ModelName" is your model class, for example, "User".
I really don't know why is it happening my model validations are not working while creating record in yii.
doesn't display any errors .
The thing is if any of the required field is empty though it passes to the display page not displaying errors
but it doesn't insert the record as all required field a not filled.
My need is display errors in the same form i.e., validations should not pass if required fields are empty.
validation works with no issues in update, issues with create form
but it inserts the record if all required field are filled.
errors displayed in update are black not red as default by yii ...... is it due to the extension am using
model rules
array('name, category, model, brand, description, price', 'required'),
array('pimg', 'file','types'=>'jpg','on'=>'create'),
array('pimg', 'file','types'=>'jpg','on'=>'update', 'allowEmpty'=>true),
controller for create
$model=new controllername;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['controllername']))
{
$model->attributes=$_POST['controllername'];
$model->pimg=CUploadedFile::getInstance($model,'pimg');
$fileName = $model->pimg;
if($model->save())
$model->pimg->saveAs('images/'.$fileName);
$this->redirect(array('display','id'=>$model->productid));
}
$this->render('create',array(
'model'=>$model,
));
view
<?php $form=$this->beginWidget('CActiveForm',array(
'id'=>'form_name',
'enableAjaxValidation'=>false,
'htmlOptions'=>array('enctype'=>'multipart/form-data'),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>60)); ?>
<?php echo $form->error($model,'name'); ?>
<?php echo $form->labelEx($model,'model'); ?>
<?php echo $form->textField($model,'model',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'model'); ?>
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textField($model,'description',array('size'=>60,'maxlength'=>256)); ?>
<?php echo $form->error($model,'description'); ?>
<?php echo $form->labelEx($model,'pimg'); ?>
<?php echo $form->hiddenField($model,'pimg',array('length'=>222)); ?>
<?php echo $form->fileField($model, 'pimg',array('id'=>'imgInput',)); ?>
<?php echo $form->error($model,'pimg'); ?>
<?php echo $form->labelEx($model,'category'); ?>
<?php echo $form->dropDownList($model,'category',$model->getCat()); ?>
<?php echo $form->error($model,'category'); ?>
<?php echo $form->labelEx($model,'brand'); ?>
<?php echo $form->textField($model,'brand',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'brand'); ?>
<?php echo $form->labelEx($model,'price'); ?>
<?php echo $form->textField($model,'price'); ?>
<?php echo $form->error($model,'price'); ?>
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
<?php $this->endWidget(); ?>
can someone PLEASE tell me how can i achieve this . Thank you
try with
array('name, category, model, brand, description, price', 'required'),
array('pimg', 'file','types'=>'jpg','on'=>'insert', 'allowEmpty'=>false),
array('pimg', 'file','types'=>'jpg','on'=>'update', 'allowEmpty'=>true),
if you redirect a page, the error will not be shown,
your code redirects anyway, if (save()) or not .
add a {} after your if
if($model->save())
{
$model->pimg->saveAs('images/'.$fileName);
$this->redirect(array('display','id'=>$model->productid));
}
I created form with yii booster, but added one empty line before textFieldRow label.
There is my code:
<div class="form">
<?php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'location-form',
'type'=>'horizontal',
));?>
<fieldset>
<pre><span class="note text-info"><?php echo Yii::t('Site', 'requiredFieldsHint'); ?></span></pre>
<?php echo $form->textFieldRow($promocode,'code',
array('maxlength'=>200,'id'=>'code'));?>
<div id='username_availability_result'></div>
</fieldset>
<fieldset>
<?php echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));?>
<?php echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));?>
<?php echo $form->textFieldRow($company,'isActive',array('maxlength'=>180,'id'=>'code'));?>
<?php echo $form->textFieldRow($company,'name',array('maxlength'=>180,'id'=>'code'));?>
<?php echo $form->textFieldRow($company,'name',array('maxlength'=>180,'id'=>'code'));?>
<?php echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));?>
<?php echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));?>
</fieldset>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>Yii::t('actions', 'Submit'),
'htmlOptions' => array('style'=>'align:center;padding: 4px 58px;'),
));
?>
</div>
<?php $this->endWidget(); ?>
</div>
Result:
On firebug:
<fieldset>
<?php echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));
echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));
echo $form->textFieldRow($company,'isActive',array('maxlength'=>180,'id'=>'code'));
echo $form->textFieldRow($company,'name',array('maxlength'=>180,'id'=>'code'));
echo $form->textFieldRow($company,'name',array('maxlength'=>180,'id'=>'code'));
echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code'));
echo $form->textFieldRow($promocode,'code',array('maxlength'=>200,'id'=>'code')); ?>
</fieldset>
use these change to merge all php in one PHP block or for easy HOTFIX use padding in CSS to fix this issue ;)
OR merge all echo in one echo
I am using ZF2 and have a form which defines a bunch of elements, and then I render it in my phtml like this:
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formlabel($form->get('description'));
echo $this->formRow($form->get('radioButton'));
echo $this->form()->closeTag();
?>
Which draws a label and a radio button.
My question is how can I then format these elements to my liking? For example make the radio buttons displayed horizontally rather than vertically and maybe change the location of the label.
There's nothing stopping you from formatting them as you have there, you could put the elements inside a list, or andd any additional markup you want to style as you wish.
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
?>
<ul class="form-list">
<li>
<div class="form-control">
<?php echo $this->formlabel($form->get('description')); ?>
<?php echo $this->formElementErrors($form->get('description')) ?>
<?php echo $this->formElement($form->get('description')); ?>
</div>
<div class="form-control">
<?php echo $this->formlabel($form->get('radioButton')); ?>
<?php echo $this->formElementErrors($form->get('radioButton')) ?>
<?php echo $this->formElement($form->get('radioButton')); ?>
</div>
</li>
</ul>
<?php echo $this->form()->closeTag() ?>
If you wanted to have control over the actual elements/inputs themselves you could do something like this:
<label>
<?php echo $form->get('radioButton')->getLabel() ?>
<input class="bob" type="radio"
name="<?php echo $form->get('radioButton')->getName() ?>"
value="<?php echo $form->get('radioButton')->getValue() ?>"
/>
</label>