CodeIgniter Forums
How can I ask for confirmation before opening an anchor? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How can I ask for confirmation before opening an anchor? (/showthread.php?tid=297)



How can I ask for confirmation before opening an anchor? - alexandervj - 11-19-2014

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.


RE: How can I ask for confirmation before opening an anchor? - Rufnex - 11-19-2014

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;"
)); ?>



RE: How can I ask for confirmation before opening an anchor? - alexandervj - 11-19-2014

Thanks very much! I'll give it a try


RE: How can I ask for confirmation before opening an anchor? - alexandervj - 11-19-2014

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


RE: How can I ask for confirmation before opening an anchor? - Rufnex - 11-19-2014

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;"
)); ?>



RE: How can I ask for confirmation before opening an anchor? - alexandervj - 11-19-2014

It returns ...

A Database Error Occurred

Error Number: 1054

Unknown column 'main' in 'where clause'


RE: How can I ask for confirmation before opening an anchor? - Rufnex - 11-19-2014

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