Jump to content

php-shawn

New Members
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

php-shawn's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Eggzorcist, I don't know if my post will actually help you at all or not, but after fussing with AJAX for WAY too long in my opinion to "get it." I started looking for an AJAX library. Most of them I found just pissed me off and didn't help or were too big or worse yet...just as complicated as every other AJAX example I'd seen only with a bunch of extra crap to deal with. Enter xajax. Head over to www.xajaxproject.org and check out the tutorial. I spent like 2 or 3 hours getting things to work as opposed to my 4 days trying to do it from scratch. I know people will argue you gotta learn to do it yourself before you use a library, but I never once seen any of those people over at my place sweeping up all the hair I pulled out. Members of their forum are very helpful when you do get stuck, but the library is very simple to use. Here is an example of a basic form submission using the xajax library: form.php <?php require_once(form.common.php'); ?> <html> <head> <?php $xajax->printJavascript(); ?> <script type="text/javascript"> function saveForm() { xajax_saveForm(xajax.getFormValues("myForm")); return false; } </script> </head> <body onLoad="xajax_showForm(); return false;"> <div id="form_container"></div> </body> </html> form.common.php <?php require_once('xajax_core/xajax.inc.php'); // THIS IS WHERE THE XAJAX LIBRARY IS $xajax = new xajax(form.server.php'); $xajax->register(XAJAX_FUNCTION, 'showForm'); $xajax->register(XAJAX_FUNCTION, 'saveForm'); ?> form.server.php <?php require_once(form.common.php'); $db = mysql_connect($HOST, $USER, $PASS); $db = mysql_select_db($DATABASE, $db); function showForm() { $response = new xajaxResponse(); // BELOW THE saveForm() REFERS TO THE JAVASCRIPT FUNCTION IN form.php $html = '<form action="javascript:void(0);" onSubmit="saveForm();" name="myForm" id="myForm"> <input type="text" name="name" id="name" value="NAME" size="31" /> <br /> <textarea cols="23" rows="7" name="description" id="description">DESCRIPTION</textarea> <br /> <input type="text" name="date" id="date" value="DD/MM/YYYY" size="31" /> <br /> <br /> <input type="submit" name="formSubmit" id="formSubmit" value="Save" /> </form>'; $response->assign('form_container', 'innerHTML', $html); return $response; } function saveTask($form) { $response = new xajaxResponse(); $name = $form["name"]; $description = $form["description"]; $date = $form["date"]; $query = "INSERT INTO `$TABLE` (`name`, `description`, `date`) VALUES ('$name', '$description', '$date')"; $query = mysql_query($query); $response->call("xajax_showForm"); return $response; } $xajax->processRequest(); ?> It looks messy at first but when you get it to function you'll be thankful for not having to write WAY too much javascript. Let me know if I can help! Shawn
  2. <form action="javascript:void(0)" onSubmit="YOURFUNCTION()">
  3. XAJAX www.xajaxproject.org
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.