- Problems accessing values in forms with jquery
- $title = $_POST['title'];
- $address = $_POST['address'];
- $new_post = array(
- 'post_title' => $title,
- 'post_content' => 'This is my post.',
- 'post_status' => 'publish',
- 'post_type' => 'post',
- 'address' => $address,
- 'geo' => $geo,
- );
- $post_id = wp_insert_post($new_post);
- update_post_meta($post_id, 'address', $address, true);
- update_post_meta($post_id, 'geo', $geo, true);
- ?>
- <?php get_header()?>
- <label>Event: </label><input id="title" type="text"/>
- <label>Address: </label><input id="address" type="text"/>
- <div id="map_canvas" style="width:500px; height:500px"></div><br/>
- <label>latitude: </label><input id="latitude" type="text"/><br/>
- <label>longitude: </label><input id="longitude" type="text"/><br/>
- <input type="submit" id="compute" onClick="getCoordinates()" value="lets try it">
- <input type="hidden" name="action" value="new_post" />
- <?php wp_nonce_field( 'new-post' ); ?>
- <?php get_footer()?>
- function getCoordinates() {
- //variables are set up on page initialization
- geocoder.geocode( { 'address': $('#address').val() }, function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- map.setCenter(results[0].geometry.location);
- alert ('latitude: ' + results[0].geometry.location.lat() + ' longitude: ' + results[0].geometry.location.lng());
- $('#latitude').val( results[0].geometry.location.lat() ) ;
- $('#longitude').val( results[0].geometry.location.lng() ) ;
- $geo = results[0].geometry.location.lat() + "," + results[0].geometry.location.lng();
- var marker = new google.maps.Marker({
- map: map,
- position: results[0].geometry.location
- });
- }
- });
- }
- <form onsubmit="getCoords()">
- ...fields...
- </form>
- <script>
- function getCoords(){
- geocoder.makeALongRequest("some","params",function(result,data,xhr){
- alert("this is the request callback");
- });
- //Always return false in the onsubmit event if you want to stop the browser from trying to POST anything
- return false;
- }