i would like to know if we have something to do to keep style in a update input with a Ajax->link?
I have this code.
<?= $this->Ajax->link('Update fields', array('controller' => 'residences', 'action' => 'edit', $residence['Residence']['id']),
array('update' => 'finance_dep_nourriture_commentaire')) ?>
and my div
<?= $this->Ajax->div('finance_dep_nourriture_commentaire') ?>
<?= $this->Form->input('Residence.finance_dep_nourriture_commentaire', array('size' => '10', 'alt' => 'cash')) ?>$/l'unité
<?= $this->Ajax->divEnd('finance_dep_nourriture_commentaire') ?>
my field have this code before the update
<div id="finance_dep_nourriture_commentaire">
<input id="ResidenceFinanceDepNourritureCommentaire" type="text" value="1600.00" alt="cash" size="10" name="data[Residence][finance_dep_nourriture_commentaire]" style="text-align: right;">mask=Object { attr="alt", mask="99.999999999999", type="reverse", more...}events=Object { keydown=[1], keypress=[1], keyup=[1], more...}handle=function()
$/l'unité
after the update
<div id="finance_dep_nourriture_commentaire">
<input id="ResidenceFinanceDepNourritureCommentaire" type="text" value="2000.00" maxlength="13" alt="cash" size="10" name="data[Residence][finance_dep_nourriture_commentaire]">
$/l'unité
how i can keep the mask, style, etc?
thanks.
Related
I'm using CodeIgniter and the MVC architecture to build a form on ExpressionEngine.
My problem is that CodeIgniter doesn't have the input date that I can use with HTML. My code is something like:
$data['cycle_begin'] = form_input('cycle_begin');
$data['cycle_month'] = form_input('cycle_month');
if(isset($_POST['submit']))
{
ee()->db->insert('exp_credit_tracker_assoc',
array(
'cycle_begin' => $_POST['cycle_begin'],
'cycle_months' => $_POST['cycle_month']
)
);
}
The view is something in the line of:
<div class="form-group">
<label for="cycle_type">cycle_type</label><?= $cycle_type ?>
</div>
<div class="form-group">
<label for="cycle_begin">cycle_begin</label><?= $cycle_begin ?>
</div>
<div class="form-group">
<label for="cycle_month">cycle_month</label><?= $cycle_month ?>
</div>
Is there any form_date which I could use or my only option is to change the input in my view file and grab the value in some way in my control file?
No there is no any form_date input type which you could use.
you can do some thing like this :
$data['cycle_begin'] = form_input('date_name',['type' =>'date']);
You can modify form_input as date input like this
<?php
$data = array(
'name' => 'mydate',
'id' => 'mydate',
'value' => '03-04-2012',
'type' => 'date',
'format' =>'m-d-Y'
);
echo form_input($data);
?>
For more : https://www.codeigniter.com/user_guide/helpers/form_helper.html
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
I get only partial data in controller. here is the situation
my action in controller that show the view with the form:
$model_sms = array();
$model_sms = new \yii\base\DynamicModel(['sms_code', 'iduser', 'mail_status', 'signup_control']);
$model_sms->addRule(['sms_code, iduser, mail_status, signup_control'], 'required');
$model_sms->addRule(['iduser, mail_status, signup_control'], 'integer');
$model_sms->addRule('sms_code', 'string', ['min' => 5, 'max' => 5]);
$model_sms->iduser = $user->id;
$model_sms->mail_status = $mail_status;
$model_sms->signup_control = 1;
return $this->renderAjax('_sms_confirmation', ['model_sms' => $model_sms]);
then the view code is here
<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
?>
<div class=" site-login">
<?php $form = ActiveForm::begin(['id' => 'frmsmsconfirm', 'action'=>'/index.php?r=site/confirmsms']); ?>
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-10">
<div class="formSeparator"><span>Enter SMS code</span></div>
<p class="logtxt">Please fill out the following fields to login:</p>
<?php
echo $form->field($model_sms, 'iduser')->hiddenInput()->label(false);
echo $form->field($model_sms, 'mail_status')->hiddenInput()->label(false);
echo $form->field($model_sms, 'signup_control')->hiddenInput()->label(false);
echo $form->field($model_sms, 'sms_code', [
'feedbackIcon' => [
'default' => 'phone',
'success' => 'ok',
'error' => 'exclamation-sign',
'defaultOptions' => ['class'=>'cw']
]
])->textInput(['placeholder'=>'Enter SMS code', 'class'=>'newxinput xinput'])->label('SMS code');
?>
</div>
<div class="col-md-1">
</div>
</div>
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-10">
<div class="scforget">
If you did not receive SMS <?= Html::a('send it again', ['site/smsresend']) ?>.
</div>
</div>
<div class="col-md-1">
</div>
</div>
<div class="row">
<div class="col-md-1">
</div>
<div class="col-md-10"><br><br>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'xsubbtn', 'name' => 'login-button']) ?>
</div><br><br>
</div>
<div class="col-md-1">
</div>
</div>
<?php ActiveForm::end(); ?>
</div>
<script>
$('#frmsmsconfirm').on('submit', function(e){
e.preventDefault();
e.stopImmediatePropagation();
var form = $(this);
alert('ajax start');
alert(form.serialize());
$.ajax({
url : form.attr('action'),
type : 'post',
data : form.serialize(),
success: function (response)
{
alert('radi a ne radi... hm');
$('#sc_content').html(response);
},
error: function ()
{
console.log('internal server error');
}
});
});
</script>
I get all correct data in alert(serialize.form), but when it is passed to another action in controller I only get sms_code, other 3 fields come blank... here is the code...
$model_sms = array();
$model_sms = new \yii\base\DynamicModel(['sms_code', 'iduser',
'mail_status', 'signup_control']);
$model_sms->addRule(['sms_code, iduser, mail_status,
signup_control'], 'required');
$model_sms->addRule(['iduser, mail_status, signup_control'],
'integer');
$model_sms->addRule('sms_code', 'string', ['min' => 5, 'max' =>
5]);
$model_sms->load(Yii::$app->request->post());
echo $model_sms->sms_code.'- xxx - <br>';
echo $model_sms->iduser.'- xxx - <br>';
echo $model_sms->mail_status.'- xxx - <br>';
echo $model_sms->signup_control.'- xxx - <br>';
exit;
Does anybod have any idea?
Thanks
You have an error at your 2 addRule() definitions:
$model_sms->addRule(['sms_code, iduser, mail_status, signup_control'], 'required');
$model_sms->addRule(['iduser, mail_status, signup_control'], 'integer');
should be:
$model_sms->addRule(['sms_code', 'iduser', 'mail_status', 'signup_control'], 'required');
$model_sms->addRule(['iduser', 'mail_status', 'signup_control'], 'integer');
The 1st parameter of addRule should be an array of attributes.
I want to make dynamic input that save an image to my website.
I use yii2-dynamicform and Kartik input file extension. But, it always save it as null.
Thank you for your help
Ps : ... is other part of my code that not relevant with this question. :)
In controller :
<?php
namespace frontend\controllers;
use Yii;
use common\models\Election;
use common\models\ElectionSearch;
use common\models\Model;
use common\models\Kandidat;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\data\ActiveDataProvider;
use yii\web\Session;
use yii\web\UploadedFile;
use yii\helpers\ArrayHelper;
class ElectionController extends Controller
{
...
public function actionCreate()
{
$model = new Election();
$modelsKandidat = [new Kandidat];
if ($model->load(Yii::$app->request->post())){
$model->save();
$modelsKandidat = Model::createMultiple(Kandidat::classname());
Model::loadMultiple($modelsKandidat, Yii::$app->request->post());
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelsKandidat) && $valid;
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
foreach ($modelsKandidat as $modelKandidat) {
$modelKandidat->id_election = $model->id_election;
if($modelKandidat->file = UploadedFile::getInstance($modelKandidat,'file'))
{
$imageName = date('dmyhis_').$modelKandidat->id_election;
$modelKandidat->file->saveAs('../../common/file/fotokandidat/'.$imageName.'.'.$modelKandidat->file->extension);
$modelKandidat->foto = $imageName.'.'.$modelKandidat->file->extension;
}
if (! ($flag = $modelKandidat->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $model->id_election]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
} else {
return $this->render('create', [
'model' => $model,
'modelsKandidat' => $modelsKandidat,
]);
}
}
...
}
In _form :
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\file\FileInput;
use yii\helpers\ArrayHelper;
use dosamigos\datepicker\DatePicker;
use wbraganca\dynamicform\DynamicFormWidget;
?>
<div class="election-form">
<?php $form = ActiveForm::begin(['options'=>['enctype'=>'multipart/form-data', 'id' => 'dynamic-form']]); ?>
...
<!-- mulai input kandidat !-->
<div class="row">
<div class="panel panel-default">
<div class="panel-heading"><h4><i class="glyphicon glyphicon-envelope"></i>Vote</h4></div>
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsKandidat[0],
'formId' => 'dynamic-form',
'formFields' => [
'nama',
'deskripsi',
'riwayat',
'file',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsKandidat as $i => $modelsKandidat): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Kandidat</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelsKandidat->isNewRecord) {
echo Html::activeHiddenInput($modelsKandidat, "[{$i}]id_kandidat");
}
?>
<div class="row">
<div class="col-sm-4">
<?= $form->field($modelsKandidat, "[{$i}]nama")->textInput(['maxlength' => true]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelsKandidat, "[{$i}]deskripsi")->textarea(['rows' => 6]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelsKandidat, "[{$i}]riwayat")->textarea(['rows' => 6]) ?>
</div>
<div class="col-sm-4">
<?= $form->field($modelsKandidat, "[{$i}]file")->fileInput() ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
</div>
<!-- selesai input kandidat !-->
...
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
It's from #shoara/#zahraj answer :
I think you forgot to specify index for your file `
foreach ($modelsKandidat as $keyindex=>$modelKandidat)
{
$modelKandidat->id_election = $model->id_election;
if ($modelKandidat->file = UploadedFile::getInstance($modelKandidat, "[{$keyindex}]file")) {
.......
}
}
see demo controller and form part,imagine $modelCatalogOption in demo is your $model = new Election(); and $modelsOptionValue is your $modelsKandidat = [new Kandidat]; if you try and check your values in your controller I'm sure you can solve this problem easily. Pay attention to actionCreate
Good day sir/maam!,
please help me to understand more about how MVC works. i am new in codeigniter and i cant really understand how the controller works when using a button. please teach me about how to navigate using button.. pls need your attention here.. :)
i have sample code here (login)
in my HTML
<?php echo validation_errors() ?>
<?php echo form_open(current_url()) ?>
<fieldset>
<div class="pull-right">
<label class="input login-input">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input placeholder = "Email Address" class = "form-control" value = "<?php echo set_value('txt_email') ?>" name = "txt_email" type="email"></input>
</div>
</label>
<label class="input login-input">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input placeholder = "Password" class = "form-control" name = "txt_password" type="password"></input>
</div>
</label>
<div class = "button-inline">
<button type="submit" class="login-button btn">Log in</button>
</div>
<hr class = "form group">
<label> You do not have an accout yet? Please click <a>here</a> to register</label>
<br>
<h6>Note: This website is for personal user only..</h6>
</div>
</fieldset>
<?php echo form_close() ?>
in my Controller
public function login()
{
$rules = array(
array('field' => 'txt_email',
'label' => 'Email',
'rules' => 'required|valid_email|callback_check_login|trim',
),
array('field' => 'txt_password',
'label' => 'Password',
'rules' => 'required|trim',
)
);
$this->form_validation->set_message('callback_check_login', 'invalid Email or Password');
if ($this->is_validated($rules)){
$this->render_client('homepage');
}
else{
$this->render_login('login', $this->data);
}
}
public function check_login(){
$where = array(
'email' => $this->input->post('txt_email'),
'password' => $this->input->post('txt_password')
);
return($this->database_model->select('tb_user', $where)) ? true : false;
}
and when i clicked the button(login), this url show
-> "http://localhost/myfirstwebsite/auth/login?txt_email=sample%40gmail.com&txt_password=sample123"
please i need your assistance! thanks!
If i understand you correct you want to call your method "login" when you press your login button. In your view replace:
<?php echo form_open(current_url()) ?>
with
<?php echo form_open('your_controller_name/login') ?>
In your confing.php you should set up your base_url:
$config['base_url'] = 'http://localhost/myfirstwebsite';
If you don't use mod_rewrite in your config.php your index_page shoud be set:
$config['index_page'] = 'index.php';
So when you click login button your form will point to your base URL plus the "your_controller_name/login" URI segments, something like this:
http://localhost/myfirstwebsite/index.php/your_controller_name/login
I am working on kendo scheduler and I need to add some extra text box and dropdowns to the create and edit of scheduler. I know extra dropdown can be added by adding the resource to scheduler, but in case of adding extra text box we have to add edit template. but in custom template I am not able to add the dropdown list for user appointment type with color specification. I have added a simple drop-down but with no color specification. I have this so far:
here is my .cshtml view code
#model List<FW.Model.UserColor>
#using Kendo.Mvc.UI;
#using Fairwater.UI.Filters
#using FW.Common.Helper
#using Fairwater.UI.Helper
<h5>Scheduler</h5>
<div class="row">
<div class="col-md-12">
#(Html.Kendo().Scheduler<FW.Model.Appointments>()
.Name("scheduler1")
.Date(new DateTime(2015, 11, 11))
.Editable(e => e.TemplateId("editor").Create(true).Confirmation(true))
.Height(600)
.Width(1000)
.EndTime(new DateTime(2025,11,11,7,00,00))
.Views(views =>
{
// views.DayView();
// views.WeekView(weekView => weekView.Selected(true));
views.MonthView(monthviw=>monthviw.Selected(true));
})
.Timezone("Etc/UTC")
//.Resources(resource =>
// {
// resource.Add(m => m.BackgroundId)
// .Title("Background")
// .DataTextField("BackgroundName")
// .DataValueField("BackgroundId")
// .Name("Background")
// .DataColorField("Color")
// .DataSource(x => x.Read(rs => rs.Action("GetBackgroundTypes", "Schedule", new { area = "Crew" })));
// })
.DataSource(d => d
.Model(m =>
{
m.Id(f => f.AppointmentId);
m.Field(f => f.Title).DefaultValue("No title");
// m.RecurrenceId(f => f.RecurrenceID);
m.Field(f => f.Title).DefaultValue("No title");
})
.Read("CrewSchedulerRead", "Schedule")
.Create("CreateAppointment", "Schedule")
.Destroy("Appointment_Destroy", "Schedule")
.Update("Appointment_Update", "Schedule")
.Events(x => x.Error("expError"))
)
)
</div>
</div>
<script id="editor" type="text/x-kendo-template">
<div class="k-edit-label">
<label for="title">Subject</label>
</div>
<div class="k-edit-field" data-container-for="title">
<input type="text" class="k-input k-textbox" name="title" data-bind="value: title">
</div>
<div class="k-edit-label">
<label for="title">Location</label>
</div>
<div class="k-edit-field" data-container-for="Location">
<input type="text" class="k-input k-textbox" name="Location" data-bind="value: Location" style="width:100%;">
</div>
<div class="k-edit-label">
<label for="BackgroundId">Background</label>
</div>
<div data-container-for="BackgroundId" class="k-edit-field">
<select id="BackgroundId" data-bind="value:BackgroundId" data-template="" data-role="dropdownlist" data-value-field="value" data-text-field="text">
#foreach (var item in Model)
{
<option style="background-color:red" value="#item.BackgroundId">#item.BackgroundName</option>
}
</select>
</div>
<div class="k-edit-label">
<label for="recurrenceRule">Repeat</label>
</div>
<div class="k-edit-field" data-container-for="recurrenceRule">
<div data-bind="value: recurrenceRule" name="recurrenceRule" data-role="recurrenceeditor"></div>
</div>
</script>
I don't now am I on the right path or not, but I think I am close of it.
Thats what I have till now
That's what I want more, the color dorpdown. Any help or suggestion would be appreciated. Thanks in advance. If anything not clear about my question please let me know in comments, I will happy to explain. Please help.
you can add how many dropdowns or any other controls using resourses as
.Resources(resource =>
{
resource.Add(m => m.OwnerID)
.Title("Trainers")
.DataTextField("EMPNAME")
.DataValueField("EMPID")
.DataColorField("COLORCODE")
.BindTo(#ViewBag.trainers);
resource.Add(m => m.TypeID)
.Title("Type")
.Name("maintype")
.DataTextField("TYPENAME")
.DataValueField("TYPECODE")
.BindTo(#ViewBag.lsttypes);
})