Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 3.42 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. phiggins: I have a form which I'll paste below.  When I am just doing standard HTML form post (method="post"), things work as I'd expect.  The form basically has 3 fields, Resource drop-down, Date Drop Down, and a Check Availability button (Submit). I choose a resource, a date, and click Check Availability (on a date that I know should return true, therefore return data to the user)...but regardless, it returns false.
  2.  
  3. Form:
  4.  
  5. <body class="tundra">
  6.         <div dojoType="dijit.form.Form" id="<?php echo $block_name?>" name="<?php echo $block_name?>" encType="multipart/form-data" action="/blocks/scheduler/check_availability.php">
  7.         <table style="border: 1px solid #9f9f9f;" cellspacing="10">
  8.  
  9.     <tr>
  10.       <td><label for="Resource">Resource:</label></td>
  11.         <td><select name="data[<?php echo $bID?>][resource]" id="data[<?php echo $bID?>][resource]" dojoType="dijit.form.ComboBox">
  12.                 <option selected></option>
  13.                 <?php $sql="SELECT * FROM hubResources";$result=mysql_query($sql);while($row=mysql_fetch_array($result)){$resource=$row['resource_name'];echo "<option>$resource</option>";}?></select>
  14.         </td>
  15.     </tr>
  16.  
  17.         <tr>
  18.                 <td><label for="Date">Date:</label></td>
  19.                 <td>
  20.                         <input type="text" name="data[<?php echo $bID?>][date]" id="data[<?php echo $bID?>][date]" value="" dojoType="dijit.form.DateTextBox" required="true" />
  21.                 </td>
  22.         </tr>
  23.         <tr>
  24.                                 <td><button dojoType="dijit.form.Button" type="submit" name="data[<?php echo $bID?>][action]" id="data[<?php echo $bID?>][action]" value="Submit">Check Availability</button></td>
  25.  
  26.         </tr>
  27.  
  28.                         <tr>
  29.                         <td><div id="response"></div></td>
  30.                         </tr>
  31. </table>
  32. </form>
  33. </body>
  34.  
  35.  
  36. <script> tag with xhrPost:
  37.  
  38. <script>
  39. function sendForm(){
  40. var form = dijit.byId("<?php echo $block_name?>");
  41. dojo.connect(form, "onSubmit", function(e){
  42. e.preventDefault();
  43. if (form.isValid()){
  44. var min = 0;
  45. var resource = dijit.byId("data[<?php echo $bID?>][resource]");
  46. if (resource.attr('value').length != min){
  47. var xhrArgs = {
  48.         form: dojo.byId("<?php echo $block_name?>"),
  49.         handleAs: "text",
  50.         load: function(data) {
  51.                 dojo.byId("response").innerHTML = "See below for available time.";
  52.                 },//closes load: function(data)
  53.         error: function(error) {
  54.                 dojo.byId("response").innerHTML = "Error.";
  55.                 }//closes error: function(error)
  56.         }//closes var xhrArgs
  57. dojo.byId("response").innerHTML = "Checking Availability..."
  58. var deferred = dojo.xhrPost(xhrArgs);
  59. }//closes if(message<min)
  60. else
  61. {
  62. alert("You must specify a message");
  63. }
  64. }//closes form.isValid
  65. else
  66. {
  67. alert("Sorry, you must fill out every field");
  68. }//closes the alert
  69. });//closes dojo.connect
  70. }; // closes function sendForm()
  71. dojo.addOnLoad(sendForm);
  72. </script>
  73.  
  74.  
  75. Firebug Post:
  76. data%5B71%5D%5Bresource%5D=Conference%20Room%20A&data%5B71%5D%5Bdate%5D=2010-08-18
  77.  
  78. Firebug Response:
  79. Sorry, there aren't any available appointments on this day.  We are either out of the office, or unavailable.<br />Click on Schedule Appointment again to try another date
  80.  
  81. Like I mentioned...the response should have been the available dates, instead it returns false...yet when I don't do this via xhrPost, it returns the available dates =\