Jump to content
Larry Ullman's Book Forums

tsatsar

Members
  • Posts

    18
  • Joined

  • Last visited

tsatsar's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. *Can't edit previous post* I understand the url, it's my return on my else. Now I'm trying this : $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $data = Yii::$app->request->post(); return $data; } else { // return ['success' => false]; return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); } And the alert(data); on my function succes from ajax : $.ajax({ url : 'index.php?r=feuille-de-jour-responsable/create' , dataType: 'json', data: obj, success: function (data, response, event, date) { alert("succes"); alert(data); }, error: function(xhr, status, error) { alert(error); } }); But the alert is empty...
  2. Without set a datatype, it says "success here" but nothing is save. I test, it work with datatype to "text" but the same. I don't understand because in firebug, I have url "GET index.php?r=feuille-de-jour-responsable/create&Date_Calendai‌​re=2016-11-10&ID_Pos‌​te_FDJ=1&ID_Categori‌​e=1&Code_Personnel=4‌​901" but with the "$feuille_de_jour_responsable->load(Yii::$app->request->post‌​())" It will be saved, isn't it ?
  3. Sorry, I change this because I need to progress on this project... Now I'm on this : http://larryullman.com/forums/index.php?/topic/18975-ajax-on-yii2-for-fullcalendar/ where you help me already
  4. I understand. But I don't understand why and how to do what I want
  5. Sorry for double post, I don't have the permission for edit. With this : error: function(xhr, status, error) { alert(error); } I have : href="http://www.hostingpics.net/viewer.php?id=831486wfvc.png
  6. Whit the function I put previously, I got just "Exception", It just did'nt work I try with this function : error: function(xhr, status, error) { alert(xhr.responseText); } And I get just my code ... http://www.hostingpics.net/viewer.php?id=952703fds.png
  7. I began to use firebug (I didn't know it, it's wonderfull ! ). And I progress a little bit : My view JS-Ajax : <div class="row"> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'ID_Categorie')->dropDownList(CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(), ['id'=>'catId']); ?> </div> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'ID_Poste_FDJ')->dropDownList(PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), ['id'=>'postId']); ?> </div> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'Code_Personnel')->dropDownList(Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(), ['id'=>'codePers']); ?> </div> </div> <?php ActiveForm::end();?> <!--<?php $JSCode = <<<EOF function(start,end) { //alert ($("select[id=catid] option:selected").text()); var title = $("select[id=codePers] option:selected"); var codePersonnel = $("select[id=codePers] option:selected").val(); var posteId = $("select[id=postId] option:selected").val(); var categorieId = $("select[id=catId] option:selected").val(); //alert($('#catid').val()); var eventData; var test = "this is an ajax test"; var obj = { Date_Calendaire : start.format(), ID_Poste_FDJ : posteId, ID_Categorie : categorieId, Code_Personnel : codePersonnel }; $.ajax({ url : 'index.php?r=feuille-de-jour-responsable/create' , dataType: 'json', data: obj, success: function (data, response, event, date) { alert("success here"); /*$('#calendar').fullCalendar('renderEvent', { title: title, start: start.format() //end: thedate1 }, true); eventData = { title: title, start: start.format(), end: start.format(), }; $('#calendar').fullCalendar('renderEvent', eventData, true); */ }, error: function () { //alert(test); //alert("Oops! Something didn't work"); alert("exception"); } }); /*if (title) { var i=start; var fin=end; //alert(fin); for (i;i<fin;i.add(1,'days')) { eventData = { title: title, start: start.format(), end: start.format(), }; $('#calendar').fullCalendar('renderEvent', eventData, true); //alert(eventData.title); //alert(eventData.start); //alert(eventData.end); } }*/ //$('#calendar').fullCalendar('unselect'); } EOF; $JSEventClick = <<<EOF function(calEvent, jsEvent, view) { alert('Event: ' + calEvent.title); alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); alert('View: ' + view.name); // change the border color just for fun //$(this).css('border-color', 'red'); } EOF; ?>--> <?= yii2fullcalendar\yii2fullcalendar::widget([ 'id' => 'calendar', 'clientOptions' => [ 'height' => 650, //'language' => 'fa', //'eventLimit' => TRUE, 'selectable' => true, 'selectHelper' => true, 'droppable' => true, 'editable' => true, //'theme'=>true, 'fixedWeekCount' => false, 'defaultDate' => date('Y-m-d'), 'eventClick' => new JsExpression($JSEventClick), 'select'=>new JsExpression($JSCode) ], //'ajaxEvents' => Url::to(['/site/jsoncalendar']), ]); ?> <?= Html::encode($JSCode); ?> <?= Html::encode($JSEventClick); ?> And my function on my controller : public function actionCreate() { $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if ($feuille_de_jour_responsable->load(Yii::$app->request->post()) && $feuille_de_jour_responsable->save()) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; //return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); return ['success' => $feuille_de_jour_responsable->save()]; } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); } } It's like the basic function create. When I click on a day, I have the "exception alert" from my Ajax function and next, nothing. I don't understand why because the URL I can see with firebug is the same that a "normal" URL with a form... Picture : http://www.hostingpics.net/viewer.php?id=419210838.png
  8. There are no error and just nothing happens, so I thing it's maybe the Url... But I don't undertand
  9. Hello, I'm using Fullcalendar for Yii2 (https://github.com/philippfrenzel/yii2fullcalendar-demo) and I want to save with Ajax the event when I click on a date. The datas commes from the dropdownlist. It seems that my code couldn't find the function in my controller, maybe it's the Url ? My view with JS and the link to my funstion Ajax on my controller : <?php $form = ActiveForm::begin(); ?> <div class="row"> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'ID_Categorie')->dropDownList(CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(), ['id'=>'catId']); ?> </div> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'ID_Poste_FDJ')->dropDownList(PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), ['id'=>'postId']); ?> </div> <div class="col-md-4"> <?= $form->field($feuille_de_jour_responsable, 'Code_Personnel')->dropDownList(Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(), ['id'=>'codePers']); ?> </div> </div> <?php ActiveForm::end();?> <?php $JSCode = <<<EOF function(start,end) { //alert ($("select[id=catid] option:selected").text()); var title = $("select[id=codePers] option:selected"); var codePersonnel = $("select[id=codePers] option:selected").val(); var posteId = $("select[id=postId] option:selected").val(); var categorieID = $("select[id=catId] option:selected").val(); //alert($('#catid').val()); var eventData; $.ajax({ url : '/site/Ajax', dataType: 'json', data: { codePersonnel : codePersonnel //dateCalendaire : start.format(), //posteId : posteID, //categorieID : categorieID // end: thedate1 }, success: function (data, response, event, date) { alert("success here"); /*$('#calendar').fullCalendar('renderEvent', { title: title, start: start.format() //end: thedate1 }, true);*/ eventData = { title: title, start: start.format(), end: start.format(), }; $('#calendar').fullCalendar('renderEvent', eventData, true); }, error: function () { alert("Oops! Something didn't work"); } }); } EOF; $JSEventClick = <<<EOF function(calEvent, jsEvent, view) { alert('Event: ' + calEvent.title); alert('Coordinates: ' + jsEvent.pageX + ',' + jsEvent.pageY); alert('View: ' + view.name); // change the border color just for fun //$(this).css('border-color', 'red'); } EOF; ?> <?= yii2fullcalendar\yii2fullcalendar::widget([ 'id' => 'calendar', 'clientOptions' => [ 'height' => 650, // 'language' => 'fa', //'eventLimit' => TRUE, 'selectable' => true, 'selectHelper' => true, 'droppable' => true, 'editable' => true, // 'theme'=>true, 'fixedWeekCount' => false, 'defaultDate' => date('Y-m-d'), 'eventClick' => new JsExpression($JSEventClick), 'select'=>new JsExpression($JSCode) ], ]); ?> <?= Html::encode($JSCode); ?> <?= Html::encode($JSEventClick); ?> And the function on my controller (SiteController) public function actionAjax(){ if(isset(Yii::$app->request->post())){ $codePersonnel = "Ajax Worked!"; echo $codePersonnel; }else{ $codePersonnel = "Ajax failed"; echo $codePersonnel; } // return Json return \yii\helpers\Json::encode($codePersonnel); } Thank you for help =) Sarah
  10. Thank you for your answer. I didn't find a solution so I'm passed to other way.
  11. *Sorry again, can't edit* I think I'm progressing. I'm using Pjax : My form : <?php Pjax::begin(); ?> <?php $form = ActiveForm::begin(); echo FormGrid::widget([ 'model'=>$feuille_de_jour_responsable, 'form'=>$form, 'autoGenerateColumns'=>true, 'rows'=>[ [ 'attributes'=>[ 'ID_Categorie'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(),'id'=>'cat-id','hint'=>'Choisir Categorie'], 'ID_Poste_FDJ'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), 'hint'=>'Choisir Poste'], /*'ID_Poste_FDJ'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\depdrop\DepDrop', 'options'=>['id'=>'poste-id'], 'pluginOptions'=>[ 'depends'=>['cat-id'], 'placeholder'=>'Select...', //'url'=>Url::to(['file:///C:/wamp64/www/test/yii/basic/controllers/PosteFdjController.php']) //'url'=>Url::to(['http://127.0.0.1:81/test/yii/basic/web/index.php?r=poste-fdj%2Findex']) 'url'=> Url::to(['/site/feuille-de-jour-responsable']) ] ],*/ 'Code_Personnel'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(),'hint'=>'Select Personnel'], ] ], [ 'attributes'=>[ //'Date_Calendaire'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']], //'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'hint'=>'Enter birthday (mm/dd/yyyy)'], 'Date_Calendaire'=>['string',Yii::$app->request->post('string'),'type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'options' => [ 'pluginOptions' => [ 'todayHighlight' => true, 'format' => 'yyyy-mm-dd', 'multidate' => true, 'multidateSeparator' => ';', ], ], 'hint'=>'Select Date', ], ] ], [ 'attributes'=>[ 'actions'=>[ // embed raw HTML content 'type'=>Form::INPUT_RAW, 'value'=> '<div>' . Html::resetButton('Reset', ['class'=>'btn btn-default']) . ' ' . Html::submitButton('Create', ['class'=>'btn btn-lg btn-primary', 'name' => 'create-button']) . '</div>' ] ], ], ] ]); ?> <?php ActiveForm::end();?> <h3><?= $stringf ?></h3> <h3><?= var_dump($stringcut) ?></h3> <?php Pjax::end(); ?> My function : public function actionCreate() { $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); //pour pjax $stringf = Yii::$app->request->post('string'); $stringcut = explode(";", $stringf); return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, 'stringcut' => $stringcut, 'stringf'=>$stringf, ]); /*$feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if ($feuille_de_jour_responsable->load(Yii::$app->request->post()) && $feuille_de_jour_responsable->save()) { return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); }*/ } I would test if I can cut this string and after that, I could save for each part of the string a new "feuilleDeJour" But it seems it do nothing. When I click on my button, the page is refreshed but nothing else... var_dump stay "Array(1) { [0]=> string(0) "" }"
  12. Sorry again for double post but I can't edit. I try something else : <?php $form = ActiveForm::begin(['feuille-de-jour-responsable/create']); echo FormGrid::widget([ 'model'=>$feuille_de_jour_responsable, 'form'=>$form, 'autoGenerateColumns'=>true, 'rows'=>[ [ 'attributes'=>[ 'ID_Categorie'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>CategorieFdj::find()->select(['Nom', 'ID_Categorie'])->indexBy('ID_Categorie')->column(),'id'=>'cat-id','hint'=>'Choisir Categorie'], 'ID_Poste_FDJ'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>PosteFdj::find()->select(['Nom_Poste_FDJ', 'ID_Poste_FDJ'])->indexBy('ID_Poste_FDJ')->column(), 'hint'=>'Choisir Poste'], /*'ID_Poste_FDJ'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\depdrop\DepDrop', 'options'=>['id'=>'poste-id'], 'pluginOptions'=>[ 'depends'=>['cat-id'], 'placeholder'=>'Select...', //'url'=>Url::to(['file:///C:/wamp64/www/test/yii/basic/controllers/PosteFdjController.php']) //'url'=>Url::to(['http://127.0.0.1:81/test/yii/basic/web/index.php?r=poste-fdj%2Findex']) 'url'=> Url::to(['/site/feuille-de-jour-responsable']) ] ],*/ 'Code_Personnel'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>Personnel::find()->select(['Nom_Personnel', 'Code_Personnel'])->indexBy('Code_Personnel')->column(),'hint'=>'Select Personnel'], ] ], [ 'attributes'=>[ //'Date_Calendaire'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter username...']], //'Date_Calendaire'=>['type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'hint'=>'Enter birthday (mm/dd/yyyy)'], 'Date_Calendaire'=>['string',Yii::$app->request->post('string'),'type'=>Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\DatePicker', 'options' => [ 'pluginOptions' => [ 'todayHighlight' => true, 'format' => 'yyyy-mm-dd', 'multidate' => true, 'multidateSeparator' => ' ; ', ], ], 'hint'=>'Select Date', ], ] ], [ 'attributes'=>[ 'actions'=>[ // embed raw HTML content 'type'=>Form::INPUT_RAW, 'value'=> '<div>' . Html::resetButton('Reset', ['class'=>'btn btn-default']) . ' ' . Html::submitButton('Create', ['class'=>'btn btn-lg btn-primary', 'name' => 'create-button']) . '</div>' ] ], ], ] ]); ?> <?php ActiveForm::end();?> And my create function : public function actionCreate() { $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if ($feuille_de_jour_responsable->load(Yii::$app->request->post()) && $feuille_de_jour_responsable->save()) { return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); } } And I remove the rules. Now I have this error : SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value: '2016-09-28 ; 2016-09-15 ; 2016-09-13' for column 'Date_Calendaire' at row 1 The SQL being executed was: INSERT INTO `feuille_de_jour_responsable` (`ID_Categorie`, `ID_Poste_FDJ`, `Code_Personnel`, `Date_Calendaire`) VALUES (1, 1, 4901, '2016-09-28 ; 2016-09-15 ; 2016-09-13') I need to cut the string '2016-09-28 ; 2016-09-15 ; 2016-09-13' for separate the different dates. But I don't know how it can work to save multiple...
  13. *Sorry for multiple post, I can't edit* I try again with the function create from yii (I don't know why, I try before post :/ ) My funcion create : public function actionCreate() { $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if ($feuille_de_jour_responsable->load(Yii::$app->request->post()) && $feuille_de_jour_responsable->save()) { return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); } } I try to save multiple "Feuille de jour" in same time but it didn't work. There is my fuction create now : public function actionCreate() { /* $feuille_de_jour_responsable = new FeuilleDeJourResponsable(); if ($feuille_de_jour_responsable->load(Yii::$app->request->post()) && $feuille_de_jour_responsable->save()) { return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $feuille_de_jour_responsable, ]); }*/ $count = count(Yii::$app->request->post('FeuilleDeJourResponsable', [])); $array_feuille_de_jour_responsable = [new FeuilleDeJourResponsable()]; for($i = 1; $i < $count; $i++) { $array_feuille_de_jour_responsable[] = new FeuilleDeJourResponsable(); } if (FeuilleDeJourResponsable::loadMultiple($array_feuille_de_jour_responsable,Yii::$app->request->post(),"FeuilleDeJourResponsable")) { foreach ($array_feuille_de_jour_responsable as $feuille) { $feuille->save(false); } return $this->redirect('index'); //return $this->redirect(['view', 'Date_Calendaire' => $feuille_de_jour_responsable->Date_Calendaire, 'ID_Poste_FDJ' => $feuille_de_jour_responsable->ID_Poste_FDJ, 'ID_Categorie' => $feuille_de_jour_responsable->ID_Categorie, 'Code_Personnel' => $feuille_de_jour_responsable->Code_Personnel]); } else { return $this->render('create', [ 'feuille_de_jour_responsable' => $array_feuille_de_jour_responsable, ]); } } With it, I have an error : " Invalid Configuration – yii\base\InvalidConfigException Either the 'formName' has to be set or a valid 'model' property must be set extending from '\yii\base\Model'." Someone have an idea?
  14. I forgot to say : when I click on submit, the page reroll but nothing more...
×
×
  • Create New...