Development

Changeset 8451

You must first sign up to be able to contribute.

Changeset 8451

Show
Ignore:
Timestamp:
04/14/08 17:06:16 (1 year ago)
Author:
FabianLange
Message:

added confirm option to link_to_function (closes #3330 , partially #307 as well)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/helper/JavascriptHelper.php

    r8395 r8451  
    8282   * Examples: 
    8383   *   <?php echo link_to_function('Greeting', "alert('Hello world!')") ?> 
    84    *   <?php echo link_to_function(image_tag('delete'), "if confirm('Really?'){ do_delete(); }") ?> 
     84   *   <?php echo link_to_function(image_tag('delete'), "do_delete()", array('confirm' => 'Really?')) ?> 
    8585   */ 
    8686  function link_to_function($name, $function, $html_options = array()) 
     
    8989 
    9090    $html_options['href'] = isset($html_options['href']) ? $html_options['href'] : '#'; 
    91     $html_options['onclick'] = $function.'; return false;'; 
     91    if ( isset($html_options['confirm']) ) 
     92    { 
     93      $confirm = escape_javascript($html_options['confirm']); 
     94      $html_options['onclick'] = "if(confirm('$confirm')){ $function;}; return false;"; 
     95    } 
     96    else 
     97    { 
     98      $html_options['onclick'] = $function.'; return false;'; 
     99    } 
    92100 
    93101    return content_tag('a', $name, $html_options); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.