Welcome Guest, Not a member yet? Register   Sign In
How can I ask for confirmation before opening an anchor?
#1

(This post was last modified: 11-19-2014, 11:10 AM by alexandervj.)

I have an anchor...
Code:
<?php echo anchor("main/confirmSent/$r->Submitted", 'Mark Sent', 'class="button icon approve"'); ?>
which updates the database, but I would like it to ask for confirmation first. Do I need to use JavaScript to do this? I know this isnt a JavaScript forum but I'm not sure how I would integrate the standard JavaScript confirm dialogue with this CodeIgniter anchor. Any help would be appreciated.
Reply
#2

For that you have to use JavaScript as the folowing native e.g.

Code:
<a href="#" onclick="if (confirm('Wollen Sie diese Domain wirklich löschen?')) { location.href = 'your_link'; } return false;">
My Link
</a>

Your e.g. should work like that (untested, because i never use a helper like that).

PHP Code:
<?php echo anchor("main/confirmSent/$r->Submitted"'Mark Sent', array(
    
'class' => 'button icon approve',
    
'onclick' => "if (confirm('Wollen Sie diese Domain wirklich löschen?')) { location.href = 'your_link'; } return false;"
)); ?>

Reply
#3

Thanks very much! I'll give it a try
Reply
#4

Thanks, it almost works, I just cant seem to get the your_link part right.
Ive tried

<?php echo anchor("main/confirmSent/$r->Submitted", 'Mark Sent', array(
'class' => 'button icon approve',
'onclick' => "if (confirm('Are you sure you want to mark as sent?')) { location.href = 'main/confirmSent/$r->Submitted'; } return false;"
)); ?>

and

<?php echo anchor("main/confirmSent/$r->Submitted", 'Mark Sent', array(
'class' => 'button icon approve',
'onclick' => "if (confirm('Are you sure you want to mark as sent?')) { location.href = 'achnor(\"main/confirmSent/$r->Submitted\")'; } return false;"
)); ?>

the first one brings up the confirmation dialogue but doesnt go to the right place, the second goes to the right place but the dialogue doesnt come up.
Thanks again
Reply
#5

(This post was last modified: 11-19-2014, 01:47 PM by Rufnex.)

try this

PHP Code:
<?php echo anchor('main/confirmSent/'.$r->Submitted'Mark Sent', array(
'class' => 'button icon approve',
'onclick' => "if (confirm('Are you sure you want to mark as sent?')) { location.href = 'main/confirmSent/".$r->Submitted."'; } return false;"
)); ?>

Reply
#6

It returns ...

A Database Error Occurred

Error Number: 1054

Unknown column 'main' in 'where clause'
Reply
#7

You must have an error in your update query .. it searches for an column main that isn't in your table. maybe you have to set the link in the javascript with as slash .... location.href = '/main

Reply




Theme © iAndrew 2016 - Forum software by © MyBB