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

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.07 KB  |  hits: 12  |  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. Problems accessing values in forms with jquery
  2. $title = $_POST['title'];
  3. $address = $_POST['address'];
  4.  
  5. $new_post = array(
  6.      'post_title' => $title,
  7.      'post_content' => 'This is my post.',
  8.      'post_status' => 'publish',
  9.      'post_type' => 'post',
  10.      'address' => $address,
  11.      'geo' => $geo,
  12.   );
  13.  
  14. $post_id = wp_insert_post($new_post);
  15.  
  16. update_post_meta($post_id, 'address', $address, true);
  17. update_post_meta($post_id, 'geo', $geo, true);  
  18.  
  19. ?>
  20.  
  21. <?php get_header()?>
  22.  
  23.     <label>Event: </label><input id="title"  type="text"/>
  24.     <label>Address: </label><input id="address"  type="text"/>
  25.     <div id="map_canvas" style="width:500px; height:500px"></div><br/>
  26.     <label>latitude: </label><input id="latitude" type="text"/><br/>
  27.     <label>longitude: </label><input id="longitude" type="text"/><br/>
  28.     <input type="submit" id="compute" onClick="getCoordinates()" value="lets try it">
  29.  
  30.     <input type="hidden" name="action" value="new_post" />
  31.     <?php wp_nonce_field( 'new-post' ); ?>
  32.  
  33.  
  34. <?php get_footer()?>
  35.        
  36. function getCoordinates() {
  37. //variables are set up on page initialization  
  38.     geocoder.geocode( { 'address': $('#address').val() }, function(results, status) {
  39.       if (status == google.maps.GeocoderStatus.OK) {
  40.         map.setCenter(results[0].geometry.location);
  41.         alert ('latitude: ' + results[0].geometry.location.lat() + ' longitude: ' + results[0].geometry.location.lng());
  42.         $('#latitude').val( results[0].geometry.location.lat() ) ;
  43.         $('#longitude').val( results[0].geometry.location.lng() ) ;
  44.         $geo =  results[0].geometry.location.lat() + "," + results[0].geometry.location.lng();
  45.         var marker = new google.maps.Marker({
  46.         map: map,
  47.         position: results[0].geometry.location
  48.  
  49.       });
  50.       }
  51.       });
  52. }
  53.        
  54. <form onsubmit="getCoords()">
  55. ...fields...
  56. </form>
  57. <script>
  58. function getCoords(){
  59.  
  60. geocoder.makeALongRequest("some","params",function(result,data,xhr){
  61.   alert("this is the request callback");
  62.   });
  63.  
  64. //Always return false in the onsubmit event if you want to stop the browser from trying to POST anything
  65. return false;
  66. }