Need Idea for confirm before delete using confirm - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1) +--- Forum: Lounge (https://forum.codeigniter.com/forumdisplay.php?fid=3) +--- Thread: Need Idea for confirm before delete using confirm (/showthread.php?tid=69967) |
Need Idea for confirm before delete using confirm - googlemy - 02-04-2018 Hi CI Team, I need yours idea how to solve this, When I click "Delete" system automatically deleted without confirm. PHP Code: <a href="'.site_url("admin/delete_user/" . $r->ID . "/" . $this->security->get_csrf_hash()).'" class="btn btn-danger btn-sm" onclick="return confirm();">Delete</a> Code: <script type="text/javascript"> Source: https://sweetalert.js.org/ Thanks RE: Need Idea for confirm before delete using confirm - wishmaster - 02-04-2018 Here example I use on my project. Place below event into <button> onclick="confirm('A you shure?') ? $('#form').submit() : false;" RE: Need Idea for confirm before delete using confirm - InsiteFX - 02-04-2018 I always have a field in the table so that I can do soft deletes. It will flag the record as deleted but it really is not deleted. RE: Need Idea for confirm before delete using confirm - dave friend - 02-04-2018 There are several problems but the first to address is the use of a whole bunch of "deprecated" options. Deprecated is in quotes because that's what Sweet Alert calls them. To me that implies "You can use them by you shouldn't", but in reality is seems they don't work at all. That's my experience when obtaining the library via the CDN. Code: <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script> Perhaps you are using an older version that was installed using npm? If so, you should upgrade that install. What I suggest here is based on using the script tag shown above. The next issue I see is how you define the function that responds to the dialog. Maybe you're using old syntax. The current syntax requires you attach a handler to the promise that swal() returns. Then there is the problem of using an anchor tag to go to the delete method. The way you have it structured that link will ALWAYS be followed even if you say "No" in the confirm dialog. It's also currently considered "bad practice" to use inline JavaScript as you by defining the "onClick" property of the anchor tag. Wow, I feel like I am really slamming you but that's not my intent. Sorry. Below is controller and view code to demonstrate something that works and addresses all the issues I observe. I mocked up values to send to the delete method and adjusted URIs to work with this test. To the best of my understanding this does what you seek to do. Controller Swal_test.php PHP Code: <?php The view file: swaltest_v.php PHP Code: <!DOCTYPE html> Hope this helps. |