php


How to create a confirm box with Twig and Symfony2 to redirect the user to page


When pushing a delete button, i'd like an alert to pop up to make sure the user didn't make any mistake.
So, In codeIgniter I had this that worked well:
Button:
<td><a class='Right btn btn-danger' onClick="ConfirmMessage('news', <?php echo $new->id ?>,'news')">
<i class="icon-remove-sign icon-white"></i>
</a></td>
Javascript:
function ConfirmMessage(type, id, types) {
if (confirm("Are you sure you want to delete this "+type+" ?")) { // Clic sur OK
document.location.href='<?php echo site_url(); ?>/'+types+'/delete/'+id;
}
}
But now, with Symfony2, I can't do this:
Button
<td><a class='Right btn btn-danger' onClick="ConfirmMessage('artist', {{ artist.id }},'news')">
<i class="icon-remove-sign icon-white"></i>
</a></td>
Javascript
function ConfirmMessage(type, id, types) {
if (confirm("Are you sure you want to delete this "+type+" ?")) { // Clic OK
document.location.href="{{ path('ymtest_Delete'"+types+", {'id': "+id+"}) }}";
}
}
Since I get an error when Symfony wants to generate a url.
What could be a solution ?
Thanks
you can't write
document.location.href="{{ path('ymtest_Delete'"+types+", {'id': "+id+"}) }}";
you are mixing twig functions and javascript functions.
Twig will be parsed and compiled on backend
Javascript will be executed on your client side after the html page is received
You will have to generate and assign each url type to a javascript variable.
a more elegant way to do that would be to store your url and messages in data attributes
<a class="Right btn btn-danger" data-url="{{ path('ymtest_EditMusician', {'id': artist.id}) }}" data-message="Are you sure you want to delete this type ?" ></a>
you can now bind your event click with javscript and retrieve your data attributes values. No more javascript tests

Related Links

Add attachment to e-mail - php mail [duplicate]
Getting an error when trying to import MySQL dump to new db
SELECT product variants SQL
Getting a select option instead of different buttons php class
How do you retrieve data from an external api in a wordpress plugin?
Mark Moodle activity as complete from within the Activity
How to fix Laravel BadMethodCallException when using Entrust
Cloudflare Header returning IPV6 Address
How to structure a database for a survey application?
laravel search engine using quarry but the thing is its not accurate
DateTime comparison not working PHP [duplicate]
Where Doctrine saves cache in Zend Framework 3 and how to change it's location?
Login system , read id and password then login
PHP (Drupal) - Update node when value has changed
How to avoid usage of “require_once” in ZF1 project with _old style_ library?
Notice: Undefined index: HTTPS even when running on HTTPS [duplicate]

Categories

HOME
python-2.7
embedded-resource
yql
mathematical-optimization
header
tfs2015
flurry
sentry
phpseclib
gtk
clickable-image
fasm
nexus3
lapack
parsley.js
amazon-emr
amazon-elb
asp.net-core-1.0
heap-dump
closures
user-defined-types
mixpanel
cocos2d-android
xsl-fo
jpa-2.1
fusetools
marquee
bobo-browse.net
materialize
matlab-app-designer
devtools
autoencoder
ftp-server
uivisualeffectview
extbase
selenide
icepdf
distributed-caching
optionaldataexception
apache-toree
code-push
audio-converter
common-table-expression
.net-micro-framework
photoswipe
android-webservice
popen
patternlab.io
network-protocols
lvalue
finder
haraka
google-identity-toolkit
tsqlt
qtcpsocket
node-glob
rails-engines
vaadin4spring
android-expansion-files
certificate-authority
enunciate
ui4j
ora-04091
calcite
mixins
wso2ml
android-handler
com0com
console.log
whitespace-language
fuseesb
prism-4
innerhtml
nsmutabledata
dos2unix
ildasm
wicket-1.5
berkeley-db-xml
nidaqmx
angular-ui-select
webautomation
two.js
redpitaya
incognito-mode
xmi
eclim
application-server
iirf
oscilloscope
days
dojo-1.9
live-wallpaper
zotonic
sigar
snackjs
getopts
simile
aptitude
outlook-2007-addin
resharper-5.0
ntruencrypt

Resources

Encrypt Message