Welcome Guest, Not a member yet? Register   Sign In
Confirm dialog helper
#1

[eluser]Unknown[/eluser]
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:
Code:
function vhconfirm(v,m)
        {
            if( v )
            {
                var f =  document.createElement("form");document.body.appendChild(f);f.method = "POST";f.action = $("#" + v ).attr( "href" );f.submit();
            } else
            {
                return false;
            }
        }

And this one your helper dir.

confirm_helper.php
Code:
<?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:
Code:
<?=confirm( 'blog/delete/'.$row->group_id , 'Delete' , 'conf'.$row->blog_id , array( 'class' => 'delete' ) , array( 'dialog' => 'Delete blog entry'.$row->entry_name.'?' ) )?>


Messages In This Thread
Confirm dialog helper - by El Forum - 10-10-2007, 02:38 AM
Confirm dialog helper - by El Forum - 10-10-2007, 04:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB