EllisLab text mark
Advanced Search
     
Confirm dialog helper
Posted: 10 October 2007 05:38 AM   [ Ignore ]
Joined: 2006-07-14
2 posts

This create confirm dialog link ( you want confirm delete or something). Use it like ci orginal anchor(), but add few extra params. Needs jQuery and jQuery plugin: Impromptu

Add this inside your head tags:

function vhconfirm(v,m)
        
{
            
if( )
            
{
                
var =  document.createElement("form");document.body.appendChild(f);f.method "POST";f.action = $("#" ).attr"href" );f.submit(); 
            
else 
            
{
                
return false;
            
}
        } 

And this one your helper dir.

confirm_helper.php

<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

    
/**
    * confirm dialog helper
    * 
    * autoload helpers confirm, url 
    * example;
    * $attr = array( 'class' => 'delete' ) // just like Ci anchor();
    * $id = unique id to anchor
    * call this "confirm( 'item/delete' , 'Title' , $id ,$attr , array( ' dialog' => 'Confirm box text' ,' btrue' => 'true button text', bfalse => 'false button text'  ) );"
    * 
    * requiments:
    *     jQuery www.jquery.com
    *    plugin Impromptu   http://trentrichardson.com/Impromptu/
    *
    * @ access public
    * @ param string            //  url if confirm is true
    * @ param intger            // id
    * @ param string            // text to confirm box title
    * @ param arr[optional]         //  defaults array( ' dialog' => 'Confirm delete?' ,' btrue' => 'Ok', bfalse => Cancel'  )
    * @ return string            // return anchor
    **/
    
function confirm$uri $title$id $attr $attr2 = array() )
    
{
        $dialog     
array_key_exists'dialog' ,$attr2 ) ?  $attr2['dialog''Confirm delete?';
        
$but_true     array_key_exists'btrue' ,$attr2 ) ?  $attr2['btrue''Ok';
        
$but_false     array_key_exists'bfalse'$attr2 ) ?  $attr2['bfalse''Cancel';
        
$attr['id'$id;
        
$attr['onclick'"[removed] $.prompt( '".$dialog."' ,{ callback: vhconfirm , buttons: { ".$but_true.": '".$attr['id']."' , ".$but_false.": false } }); return false;";
        return 
anchor$uri $title $attr );
    
}
?> 

And then use it like:

<?=confirm'blog/delete/'.$row->group_id 'Delete' 'conf'.$row->blog_id , array( 'class' => 'delete' ) , array( 'dialog' => 'Delete blog entry'.$row->entry_name.'?' ) )?> 
 
Posted: 10 October 2007 07:57 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-11
2985 posts

Always made things like this in Darkbasic, im suprised I never thought of it in JS! Thanks for this mate.

 Signature 

————————
Blog | Twitter | GitHub | BitBucket
————————-
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management