Advertisement
Guest User

len kun

a guest
Jul 29th, 2009
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.38 KB | None | 0 0
  1. <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. if( ! function_exists('form_ajax'))
  4. {
  5.     function form_ajax($form_id, $method = 'POST', $update = '', $create = true)
  6.     {
  7.         $automake_div = (!empty($update) && $create);
  8.         $method = ($method === 'POST') ? 'POST' : 'GET';
  9.         return
  10.         ($automake_div ? '<div id="'.$update.'"></div>' : '').'
  11.         <script type="text/javascript" src="http://yui.yahooapis.com/combo?2.7.0/build/yahoo-dom-event/yahoo-dom-event.js&2.7.0/build/connection/connection-min.js&2.7.0/build/selector/selector-min.js"></script>
  12.         <script type="text/javascript" charset="utf-8">
  13.         var doNotSubmit = function(e) {
  14.             YAHOO.util.Event.preventDefault(e);
  15.             makeRequest();
  16.         }
  17.         YAHOO.util.Event.addListener(YAHOO.util.Selector.query("#'.$form_id.' input[type=submit]"), "click", doNotSubmit);
  18.  
  19.         '.($automake_div ? 'var div = document.getElementById("'.$update.'");' : '').'
  20.         var callback = {
  21.             success: function(o) {
  22.                 if(o.responseText !== undefined) {
  23.                     div.innerHTML = o.responseText;
  24.                 }
  25.             }
  26.         }
  27.         var sUrl = document.getElementById("'.$form_id.'").action;
  28.                
  29.         function makeRequest() {
  30.             YAHOO.util.Connect.setForm("'.$form_id.'");
  31.             YAHOO.util.Connect.asyncRequest("'.$method.'", sUrl, callback);
  32.         }
  33.         </script>
  34.         ';
  35.     }
  36. }
  37.  
  38. /* End of MY_form_helper.php */
  39. /* Location: ./system/application/helpers/MY_form_helper.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement