Advertisement
KzDrew

sandbox_ajax_form.php

Aug 15th, 2013
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.27 KB | None | 0 0
  1.  <?php
  2.  
  3.  $config = array();
  4.  $config['url_to_scripts'] = 'https://someserver.com/av/mobile/resources/js';
  5.  
  6.  error_log('count: '. (count($_POST)). ', name: '.$_POST['name'].', email: '. $_POST['email'].', memory: '.$_POST['memory']);
  7.  
  8.  if(count($_POST) > 0){
  9.  
  10.  
  11.     header('Content-type: text/javascript');
  12.  
  13.     $json = array(
  14.     'success'       => false,
  15.     'result'        => 0
  16.  
  17.  
  18.     );
  19.  
  20.  
  21.  
  22.     if(isset($_POST['name'], $_POST['email'], $_POST['memory'])){
  23.  
  24.     error_log('I have the post data I am looking for');
  25.  
  26.     $name       = $_POST['name'];
  27.     $email      = $_POST['email'];
  28.     $memory     = $_POST['memory'];
  29.  
  30.     $json['success'] = true;
  31.     $json['result']  = $name;
  32.  
  33.     }
  34.  
  35.     echo json_encode($json);
  36.  
  37.     exit;
  38.  
  39.  }
  40.  
  41.  
  42.  ?>
  43. <html>
  44. <head>
  45.  
  46. <style type="text/css">
  47.  
  48. </style>
  49.  
  50.  
  51. <!-- load the css used by the jquery-mobile library -->
  52. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
  53.  
  54.  
  55. <!-- load the jquery library -->
  56. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  57.  
  58. <!-- load the js that binds to various jqm events here, BEFORE loading jqm -->
  59. <script src="<?php echo $config['url_to_scripts'];?>/sandbox_ajax_form.js"></script>
  60.  
  61. <!-- load the jquery-mobile (jqm) library -->
  62. <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
  63.  
  64. </head>
  65. <body>
  66.  
  67.  
  68. <!-- all css, script, and page content for this page GO INSIDE THIS DIV
  69.      Caution: any script is executed each time the page is displayed (cached or new)
  70.               so this is not a good place to bind events
  71. -->
  72. <div data-role="page" id="formPage" data-theme="b" data-content-theme="b">
  73.  
  74.     <p>A link to <a href="sandbox_m1.php">sandbox_m1.php</a></p>
  75.  
  76.    <form id="form"   method="POST"  data-ajax="false" data-transition="pop" data-direction="reverse">
  77.             <fieldset>
  78.  
  79.  
  80.             <label for="name" class="ui-hidden-accessible">Name</label>
  81.             <input type="text" name="name" id="name" value=""  class="required" placeholder="Name"/>
  82.  
  83.  
  84.             <label for="email" class="ui-hidden-accessible">E-Mail</label>
  85.             <input type="email" name="email" id="email" value="" class="required" placeholder="E-Mail"/>
  86.  
  87.  
  88.             <label for="memory" class="ui-hidden-accessible">Memory</label>
  89.             <textarea name="memory" name="memory" id="memory"  class="required" placeholder="Your Memory..."></textarea>
  90.  
  91.  
  92.  
  93.             <label for="submit" class="ui-hidden-accessible">Submit</label>
  94.             <input type="submit" name="submit" id="submit" value="SEND">
  95.  
  96.              </fieldset>
  97.         </form>
  98.  
  99.  
  100.  
  101.  
  102.     <script>
  103.         console.log('script in the content area of #formPage');
  104.         /*
  105.         Strange Behavior Note:
  106.           js code placed here will get executed:
  107.           -- JUST ONCE if this is the very first page that is loaded and never again when returning to this page
  108.           -- EVERY TIME this page is displayed if this page was NOT the very first page that was loaded
  109.         */
  110.         // .. do stuff here
  111.     </script>
  112.  
  113.  
  114. </div>
  115.  
  116.  
  117.  
  118.  </body>
  119. </html>
  120.  
  121.  
  122. <?php
  123.     function dump_results($var_2_dump, $label=''){
  124.     if($label){
  125.         echo "Dumping ".$label."<br />\n";
  126.     }
  127.     echo "<pre>";
  128.     var_dump($var_2_dump);
  129.     echo "</pre>\n";
  130. }
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement