Reputation: 1
I'm using a Wordpress plugin (Work The Flow) that allows file uploads / downloads / deletion etc.
The plugin allows a user to delete any file of theirs, but doesn't ask you to confirm you really want to delete it: it just immediately deletes the file.
I'd like to add in something to ensure a confirmation popup appears first.
The plugin owner pointed me to this php code in his plugin (and specifically towards btn btn-danger delete:
function getDownloadJSTemplate() {
$script = <<<DOWNLOADJSTEMPLATE
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
<td>
<span class="preview">
{% if (file.thumbnailUrl) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
{% } %}
</span>
</td>
<td>
<p class="name">
{% if (file.url) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
{% } else { %}
<span>{%=file.name%}</span>
{% } %}
</p>
{% if (file.error) { %}
<div><span class="label label-danger">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
<span class="size">{%=o.formatFileSize(file.size)%}</span>
</td>
<td>
{% if (file.deleteUrl) { %}
<button class="btn btn-danger delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}&action=load_ajax_function"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>
<i class="glyphicon glyphicon-trash"></i>
<span>Delete</span>
</button>
<input type="checkbox" name="delete" value="1" class="toggle">
{% } else { %}
<button class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancel</span>
</button>
{% } %}
</td>
</tr>
{% } %}
</script>
DOWNLOADJSTEMPLATE;
return $script;
}
Can anyone advise - assuming I can create a child .php file to do this? - how I can add a confirmation stage in? The delete button can appear many times on the page, as it appears alongside each uploaded file.
Upvotes: 0
Views: 561
Reputation: 4084
The simplest way would be to use javascript, this will prompt an alert box on the screen with OK and cancel button. to do this just add onclick inside the anchor. Something like this.
<a href="url/to/delete.asp" onclick="return confirm(' you want to delete?');">Delete</a>
If you want to do something fancy and you are using a bootstrap theme then you will have to do a bit of more work. Just follow this JSFIDDLE
Upvotes: 0