How can I add a Glyphicons Icons in the input below?
A part of the code:
class GrupoUsuarioForm{
$this->setAttributes(array(
'method' => 'POST',
'class' => 'formGrupoUsuario',
'name' => 'formGrupoUsuario'
));
$this->setInputFilter(new GrupoUsuarioInputFilter());
$dataCadastro = new Text('data_grp');
$dataCadastro->setValue(date('d/m/Y'))
->setAttributes(array(
//'style' => 'width: 20%',
'id', 'dataGrp',
'readOnly' => 'true'
));
$dataCadastro->setLabel('Data do Cadastro');
$this->add($dataCadastro);
Would like this return HTML
<label>Textbox with calendar icon</label>
<div class="input-append"><input type="text" id="" name="">
<span class="add-on"><i class="icon-calendar"></i></span></div>
Where excatly do you want put this icon?
You can render form's elements as you want.
In controller:
public function myAction()
{
return new ViewModel([
'form' => new GrupoUsuarioForm()
]);
}
In your view:
// HTML code here
...
<?php $form = $this->form; ?>
<?php $form->prepare(); ?>
<?php echo $this->form()->openTag($form); ?>
...
<?php echo $this->formLabel($form->get('data_grp')); ?>
<div class="input-group">
<div class="input-append">
<?php echo $this->formInput($form->get('data_grp')); ?>
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
</div>
...
<?php echo $this->form()->closeTag(); ?>
Related
I'm trying to create a simple inline form that displays an entry field followed by a submit button - how can I alter this existing code so that these elements display horizontally in one row? ...I've tried altering the form class but no success. Thank you in advance.
PHP
<div class="d3-mailchimp" data-block-id="<?php echo $bID; ?>">
<?php
if (isset($errors)) {
$errors->output();
}
if (isset($message)) {
echo '<p class="message">'.$message.'</p>';
} else {
?>
<form method="post" action="<?php echo $this->action('submit') ?>" onsubmit="d3_mailchimp_submit(this); return false;">
<?php $token->output('d3_mailchimp.subscribe'); ?>
<div class="form-group field">
<?php
echo $form->email('email_address', '', [
'required' => 'required',
'placeholder' => t(''),
]);
?>
</div>
<?php
if ($showTermsCheckbox) {
?>
<div class="accept-terms">
<label for="accept_terms">
<?php
echo $form->checkbox('accept_terms', 1, 0, [
'required' => 'required',
]);
?>
<?php echo $acceptTermsText; ?>
</label>
</div>
<?php
}
?>
<div class="submit-button">
<?php
echo $form->submit('submit', t('Subscribe'), [
'class' => 'button',
]);
?>
</div>
</form>
<?php
}
?>
I try load form via ajax in CJuiDialog. The form was success loaded but when I submitted form or write text, form not validate and not submit.I tried set "true" fourth parameter in renderPartialbut after then dialog window didn't open. In console, I got error
$(...).dialog is not a function
In view I have this:
Yii::app()->clientScript->registerScript(
"test",
"jQuery.ajax({
type: 'POST',
url: '".$this->createUrl("/Site/ShowForm")."',
success: function(html){
$('#form-test').html(html);
});
",
CClientScript::POS_READY); ?>
<div id="form-test"></div>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog');
My actions in controller:
public function actionShowForm()
{
$model = new RegistrationForm;
if(Yii::app()->request->isAjaxRequest )
return $this->renderPartial('register', array('model' => $model),false,false);
}
public function actionRegister()
{
$model = new RegistrationForm;
$this->ajaxValidate($model);
$model->attributes =$_POST['RegistrationForm'];
if($model->validate())
{
$user = new User;
$user->attributes = $model->attributes;
if($user->save())
echo 1;
}
}
and my form (register.php)
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'register-form',
//'enableClientValidation'=>true,
'enableAjaxValidation' => true,
'clientOptions' => array(
//'validateOnSubmit' => true,
'validateOnChange' => true
),
'action' => array('site/Register'),
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<?php echo $form->labelEx($model, 'first_name'); ?>
<?php echo $form->textField($model, 'first_name'); ?>
<?php echo $form->error($model, 'first_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'last_name'); ?>
<?php echo $form->textField($model, 'last_name'); ?>
<?php echo $form->error($model, 'last_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'email'); ?>
<?php echo $form->emailField($model, 'email'); ?>
<?php echo $form->error($model, 'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'password'); ?>
<?php echo $form->textField($model, 'password'); ?>
<?php echo $form->error($model, 'password'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'Repeat password'); ?>
<?php echo $form->textField($model, 'repeat_password'); ?>
<?php echo $form->error($model, 'repeat_password'); ?>
</div>
<div>
<?php echo $form->textField($model, 'verifyCode'); ?>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->error($model, 'verifyCode'); ?>
</div>
<div class="row buttons">
<?php
echo CHtml::ajaxSubmitButton('Register', $this->createUrl("/Site/Register"), array(
'type' => 'POST',
'dataType' => 'json',
'success' => 'js:function(data){
if(data == 1){
window.location ="' . $this->createUrl('site/index') . '"
}
}',
));
?>
</div>
<?php $this->endWidget(); ?>
How Can I fix this problem?
In your controller, where you check if the request is Ajax, you should be doing the Ajax validation in there.
I found solution! I added
Yii::app()->clientScript->scriptMap = array(
'jquery.js' => false,
'jquery.ui.js' => false,
'jquery.yiiactiveform.js' => false,
);
in my actionShowForm.
I'm not sure how to describe my question. First I added a button at my CCGridview:
array(
'class'=>'CButtonColumn',
'template' => '{view}{update}{delete}{upload_image}',
'buttons' => array(
'upload_image' => array(
'label' => 'upload foto',
'url' => 'Yii::app()->createUrl("/image/create",
array("product_id" => $data->product_id))',
),
),
),
when I clicked it will bring me to the /image/create view which has a product_id value. For example on that gridview I clicked record number 7, so the url would be:
(webApp)/index.php/image/create?product_id=7
Since it rendering a partial _form so the form has the attribute according to the image table which has this attributes: id, title, filename, product_id.
So the view will be something like:
<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'filename'); ?>
<?php echo $form->fileField($model,'filename',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'filename'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'product_id'); ?>
<?php echo $form->textField($model,'product_id'); ?>
<?php echo $form->error($model,'product_id'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
My question is, how do we use the value from the url which I mentioned before is 7 (../create?product_id=7) into the product_id attribute without have to type it at provided textField?
In other word I will remove this from the view:
<div class="row">
<?php echo $form->labelEx($model,'product_id'); ?>
<?php echo $form->textField($model,'product_id'); ?>
<?php echo $form->error($model,'product_id'); ?>
</div>
But when i submitted, the form the value (7) should have been passed/saved at product_id field.
Added:
My controller actionCreate is
//...
public function actionCreate()
{
$dir = Yii::app()->basePath . '/../productimages/';
$uploaded = false;
$model=new Image();
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
$tempSave=CUploadedFile::getInstance($model,'filename');
if($model->validate())
{
$uploaded = $tempSave->saveAs($dir.'/'.$tempSave->getName());
$this->redirect(array('/products/index'));
}
}
$this->render('index', array(
'model' => $model,
'uploaded' => $uploaded,
'dir' => $dir,
));
}
That's it. Many thanks..
modify your controller this way:
if(isset($_POST['Image']))
{
$model->attributes=$_POST['Image'];
$tempSave=CUploadedFile::getInstance($model,'filename');
if($model->validate())
{
$uploaded = $tempSave->saveAs($dir.'/'.$tempSave->getName());
$this->redirect(array('/products/index'));
}
} else {
//initialize defaults
$model->product_id=intval($_GET['product_id']);
}
I need to update a modal window and show it when I click in the edit button.
CONTROLLER:
public function actionUpdateAjax($id)
{
$contratos = ZfContratos::model()->findByPk($id);
$this->renderPartial('//ZfContratos/_form_update', array('model'=>$contratos), false, true);
}
INDEX:
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'actualizar_contrato')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Actualizar contrato</h4>
</div>
<div class="modal-body">
<?php $this->renderPartial('//ZfContratos/_form_update', array('model'=>$contrato));?>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'CANCELAR',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
AND VIEW _contratos
At this moment I have this:
<?php echo CHtml::link('EDITAR', array('//ZfInmuebles/UpdateAjax', 'id'=>$data->zf_contrato_id), array('class'=>'btn', 'id'=>'vermas')); ?>
But I need that to be an ajaxbutton or ajaxlink, that refresh the div "actualizar_contrato" and show it.
This is just a reference implementation to give you an idea of how to do this, do modify as per your requirements
// your view
// Button to trigger modal
<?php echo CHtml::ajaxLink('EDITAR',array('//ZfInmuebles/UpdateAjax', 'id'=>$data-> zf_contrato_id), array(
'type'=>'POST',
"success"=>'js:function(html){
$("#actualizar_contrato >.modal-body").html(html);
$("#actualizar_contrato").modal("show");
}
'));?
.....
// modal
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'actualizar_contrato')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Actualizar contrato</h4>
</div>
<div class="modal-body">
<?php
$contrato = new ZfContratos;
$this->renderPartial('//ZfContratos/_form_update', array('model'=>$contrato));
?>
</div>
<div class="modal-footer">
<?php echo CHtml::ajaxLink('Save', // Link Text
array('//ZfContratos/update', 'id'=>$data->zf_contrato_id), //url
array(// ajaxOptions
'data'=> 'js:$("#id_of_the_form").serialize()' ,
'type'=>'POST',
'success'=>'js:function(html){$("#actualizar_contrato >.modal-body").html(html) }'
)
)
);?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'CANCELAR',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
.....
And now in your controller modify as like below
//ZfContratos Controller
public function actionUpdate(){
// Your regular logic for saving
if(Yii::app()->request->isAjaxRequest){
if($model->save()){
$this->renderPartial("_mvsavedView",array('model'=>$model)) //OR echo "Saved Successfully";
} else {
print_r($model->getErrors());
}
Yii::app()->end();
}
}
I have dropdown list where there are five or six items (here items are services). I used here ajax request which updates the id “package_id” from the URL 'url'=>$this->createUrl('servicePackage'), once I select any service item. Till now, I have done successfully. But I want that ajax should use different URL and update different id i.e. “registrationid” if I select 4th number item, otherwise it should update “package_id”.
Is it possible?
Is it possible?
The form is:
<div class="form-group">
<?php echo $form->labelEx($model,'service_id', array('class' => 'control-label col-lg-4')); ?>
<div class="col-lg-8">
<?php echo $form->dropDownList($model,'service_id',CHtml::listData(Service::model()->findAll(),'id', 'name'),
array(
'class' => 'form-control',
'prompt'=>'Select a Service',
'ajax' => array('type'=>'POST',
'url'=>$this->createUrl('servicePackage'),
'update'=>'#'.CHtml::activeId($model, 'package_id'), // ajax updates package_id, but I want ajax update registration_id if I select item no 4
'data'=>array('service_id'=>'js:this.value'),
)));
?>
</div>
<?php echo $form->error($model,'service_id'); ?>
</div>
<div class="form-group" id="packageid">
<?php echo $form->labelEx($model,'package_id', array('class' => 'control-label col-lg-4')); ?>
<div class="col-lg-8">
<?php
echo $form->dropDownList($model,'package_id',$model->getServicePackage($model->service_id),array(
'class' => 'form-control','prompt'=>'Select a Package',
'ajax' =>
array('type'=>'POST',
'url'=>$this->createUrl('packagePrice'), //url to call.
'update'=>'#price', //selector to update
'data'=>array('package_id'=>'js:this.value'),
)));
?>
</div>
<?php echo $form->error($model,'package_id'); ?>
</div>
<div class="form-group" id="registrationid">
<?php echo $form->labelEx($model,'registration_id', array('class' => 'control-label col-lg-4')); ?>
<div class="col-lg-8">
<?php
$registrants = Registration::model()->findAll();
$data = CHtml::listData($registrants,'id', function($registrants) {
return CHtml::encode($registrants->name.' ('.$registrants->id.')');
});
echo $form->dropDownList($model,'registration_id',$data,
array(
'class' => 'required form-control chzn-select',
'prompt'=>'Select a Registrant',
'ajax' => array('type'=>'POST',
'url'=>$this->createUrl('Order'), //url to call.
'update'=>'#'.CHtml::activeId($model, 'order_id'), //selector to update
'data'=>array('registration_id'=>'js:this.value'),
)
));
?>
</div>
<?php echo $form->error($model,'registration_id'); ?>
</div>