Hello guys!, I have a problem I am trying to edit a record from an index view but I want to be in a popup and then update the currend index view. Does anybody know or have a practical example?
I donât have a practical example. However, I can tell you that it is a problem related to the markup of the page rather than a CakePHP specific problem:) You should be able to use a lot of the popup examples out there.
From a quick google I found this: https://www.w3schools.com/howto/howto_js_popup.asp
Good luck
Thanks for your prompt repñy but what I am looki g for to open a controller action like edit or add in a modal window and once added or edited refresh current view or index.
Thanks!!
In fact you do not open a Controller action âeditâ in the modal
What you want to do need javascript and ajax code, something like this:
1 - In the index.ctp you have the loop to echo you entity collection passed from controller (in some sort of table, grid etc)
2 - this table/grid should have a link/button for each row (Edit) that triggers a javascript function passing the row entity ID
3 - the javascript function use ajax to request a controller action that find this entity data where ID = passed ID
4 - javascript function recive the ajax data, fill the modal form and show to the user
5 - now the edit modal form works like in the edit.ctp view, just change the redirect in the controller edit action to the index action (when the form is submited and saved redirect to index.ctp)
If you dont want the page reload in index.ctp more javascript ajax code is needed to submit the edit form via ajax too
there are plugins for this just serach: php inline row edit jquery
Hellou,
Simple way to modal add/edit window in CakePHP and JQuery:
In Default.ctp file:
<?= $this->Html->script('https://code.jquery.com/jquery-1.12.4.js') ?>
<?= $this->Html->script('https://code.jquery.com/ui/1.12.1/jquery-ui.js') ?>
<?= $this->Html->css('https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css') ?>
In view, from you have call modal edit:
<?= $this->Html->link('Edit', ['controller'=>'elements', 'action' => 'edit', $overElements->id], ['class'=>'overlay']) ?>
and bottom in this file:
script
$(document).ready(function() {
$( â#dialogModalâ ).dialog({
closeOnEscape: false,
dialogClass: ânocloseâ,
open: function(event, ui) { $(â.ui-dialog-titlebar-closeâ).hide(); },
autoOpen: false,
show: {
effect: âblindâ,
duration: 300
},
hide: {
effect: âblindâ,
duration: 300
},
modal: true,
height:560, width:800
});
$(â.overlayâ).click(function(event){
event.preventDefault();
$(â#contentWrapâ).load($(this).attr(âhrefâ));
$(â#dialogModalâ).dialog(âoptionâ, âtitleâ, $(this).attr(âtitleâ));
$(â#dialogModalâ).dialog(âoptionâ, âtitleâ, âPozycja wnioskuâ);
$(â#dialogModalâ).dialog(âopenâ);
});
});
/script
end file.
In edit ctp view file:
<?= $this->Form->create($overelement) ?>
<?= $this->Element('element for this view'); ?><a hâref=â#â id=âbtnDoneâ class=âbuttonâ>Cancel
<?= $this->Form->button(__('Save'),['id'=>'bt_save']) ?> <?= $this->Form->end() ?>script
$(document).ready(function () {
$(â#btnDoneâ).click(function () {
$(â#dialogModalâ).dialog(âcloseâ);
});
});
/script
script
$(â#OverElemAddâ).ajaxForm({
target: â#contentWrapâ,
resetForm: false,
beforeSubmit: function() {
$(â#contentWrapâ).html(âOne momentâŠâ);
},
success: function(response) {
if (response==âsavedâ)) {
$(â#dialogModalâ).dialog(âcloseâ); //close containing dialog
location.reload(); //if you want to reload parent page to show updated user
}
}
});
/script
Itâs not working it opens up edit.ctp as usual (no dialog)
What could it be?
(by the way a changed quotes because it giving me errors!!!
This is what is have in my view ctp
<?= $this->Html->link('Edit', ['controller'=>'ProduccionLaminas', 'action' => 'edit', $lamina->id], ['class'=>'overlay']) ?>inside my edit.ctp
<br>
<br>
<?= $this->Html->link('<span class="glyphicon glyphicon-arrow-left"></span> Regresar', ['action'=>'index'], ['class'=> 'btn btn-danger pull-left', 'escape'=> false]) ?>
<br>
<div class="page-header">
<h2><?= 'Edit Produccion Lamina' ?></h2>
</div>
<?= $this->Form->create($produccionLamina) ?>
<fieldset>
<?= $this->element('ProduccionLaminas/fields') ?>
</fieldset>
<a href="#" id="btnDone" class="button">Cancel
<?= $this->Form->button(__("Save"),["id"=>"bt_save"]) ?>
<?= $this->Form->end() ?>
</div>
Edit/add modal window in CakePHP3
I share sample source: http://leszek-klich.pl/Example_modal.tar.gz (layout, views and controllers).
Regards
Leszek Klich
Just a guess, but try closing your anchor tag. Instead of this:
<a href="#" id="btnDone" class="button">Cancel
use this:
<a href="#" id="btnDone" class="button">Cancel</a>
See this https://drive.google.com/file/d/0B1_PFw--3o74TC16eXRBYXZBNFk/view Just a quick rough example.
I have a popup, do the edit and in the time the popup closes the table is refreshed with the new data. But there are many ways to do it. To keep it simple for yourself you could take a look at x-editable https://vitalets.github.io/x-editable/
To try to give a lesson on this on a forum is not realistic, it took some of these folks years to gain the knowledge. But there are many free tutorials on the web.
It is not a cakephp thing, same in any php framework, asp.net, jsp servlet, etc. It is a javascript and ajax thing that uses the server side code to do the update.
Hello @SKyer How are you?
Url no found
Thank you.