preFunctionTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. require_once("../xajax.inc.php");
  3. function testRegularFunction($formData)
  4. {
  5. $objResponse = new xajaxResponse();
  6. $objResponse->addAlert("formData: " . print_r($formData, true));
  7. $objResponse->addAssign("submittedDiv", "innerHTML", nl2br(print_r($formData, true)));
  8. return $objResponse->getXML();
  9. }
  10. function myPreFunction($funcName, $args)
  11. {
  12. $objResponse = new xajaxResponse();
  13. if ($args[1] == 0) {
  14. $objResponse->addAlert("This is from the pre-function, which will now call " . $funcName);
  15. return $objResponse;
  16. }
  17. $objResponse->addAlert("This is from the pre-function, which will now end the request.");
  18. return array(false, $objResponse);
  19. }
  20. class myPreObject
  21. {
  22. var $message = "This is from the pre-function object method";
  23. function preMethod($funcName, $args)
  24. {
  25. $objResponse = new xajaxResponse();
  26. if ($args[1] == 0) {
  27. $objResponse->addAlert($this->message . ", which will now call " . $funcName);
  28. return $objResponse;
  29. }
  30. $objResponse->addAlert($this->message . ", which will now end the request.");
  31. return array(false, $objResponse);
  32. }
  33. }
  34. $xajax = new xajax();
  35. //$xajax->debugOn();
  36. if (@$_GET['useObjects'] == "true") {
  37. $preObj = new myPreObject();
  38. $xajax->registerPreFunction(array("myPreFunction", &$preObj, "preMethod"));
  39. }
  40. else {
  41. $xajax->registerPreFunction("myPreFunction");
  42. }
  43. $xajax->registerFunction("testRegularFunction");
  44. $xajax->processRequests();
  45. ?>
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  47. "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-transitional.dtd">
  48. <html xmlns="http://www.w3.org/1999/xhtml">
  49. <head>
  50. <title>Pre-function Test | xajax Tests</title>
  51. <?php $xajax->printJavascript("../") ?>
  52. </head>
  53. <body>
  54. <h2><a href="index.php">xajax Tests</a></h2>
  55. <h1>Pre-function Test</h1>
  56. <form id="testForm1" onsubmit="return false;">
  57. <p><input type="text" id="textBox1" name="textBox1" value="This is some text" /></p>
  58. <p><input type="submit" value="Normal request" onclick="xajax_testRegularFunction(xajax.getFormValues('testForm1'), 0); return false;" /></p>
  59. <p><input type="submit" value="Pre-function should end request" onclick="xajax_testRegularFunction(xajax.getFormValues('testForm1'), 1); return false;" /></p>
  60. </form>
  61. <p><a href="preFunctionTest.php?useObjects=true">Reload using object</a></p>
  62. <div id="submittedDiv"></div>
  63. </body>
  64. </html>