Title: Add action hook function.
Last modified: August 21, 2016

---

# Add action hook function.

 *  [writegnj](https://wordpress.org/support/users/writegnj/)
 * (@writegnj)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/)
 * how do I add action hook on form submit. In my understanding the code below makes
   sense but clearly it’s not working which means I’m doing it wrong. Can someone
   help me out with me?
    I want to store data from custom fields to DB on form submit
   from front-end.
 * this is the code I have on function.php in custom theme folder.
 *     ```
       function add_location_info( $form_id, $post_id, $form_settings ){
       $fullstreet = $_POST['cf_street_number']. ' ' .$_POST['cf_route'];
           //enter information into the custom table //
           $wpdb->insert( $wpdb->prefix . 'places_locator',
       		array(
       				'post_id'		=> $post->ID,
       				'post_type' 	=> $post->post_type,
       				'post_title' 	=> $post_title,
       				'post_status'	=> $_POST['post_status'],
       				'street'		=> $fullstreet,
       				'city' 			=> $_POST['cf_locality'],
       				'state' 		=> $_POST['cf_administrative_area_level_1'],
       				'zipcode' 		=> $_POST['cf_postal_code'],
       				'country' 		=> $_POST['cf_country'],
       				'lat' 			=> $_POST['cf_lat'],
       				'long' 			=> $_POST['cf_lng'],
       			)
       		);
   
       }
       add_action("wpuf_post_submission", "add_location_info", 10, 3);
       add_action( 'wpuf_add_post_after_insert', 'wpuf_post_submission' );
       ```
   
 * [http://wordpress.org/plugins/wp-user-frontend/](http://wordpress.org/plugins/wp-user-frontend/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [mainpart](https://wordpress.org/support/users/mainpart/)
 * (@mainpart)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/#post-4522157)
 * there is no such hook as wpuf_post_submission.
    you need:
 *     ```
       function add_location_info($post_id){
       $wpdb->insert( ... insert variables from $_POST ... to $post_id )
       }
       add_action( 'wpuf_add_post_after_insert', "add_location_info" );
       ```
   
 *  Thread Starter [writegnj](https://wordpress.org/support/users/writegnj/)
 * (@writegnj)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/#post-4522165)
 * I’m not familiar with action hook yet. so should I fix like this?
 *     ```
       function add_location_info($post_id){
           $fullstreet = $_POST['cf_street_number']. ' ' .$_POST['cf_route'];
           //enter information into the custom table //
           $wpdb->insert( $wpdb->prefix . 'places_locator',
       		array(
       				'post_id'		=> $post->ID,
       				'post_type' 	=> $post->post_type,
       				'post_title' 	=> $post_title,
       				'post_status'	=> $_POST['post_status'],
       				'street'		=> $fullstreet,
       				'city' 			=> $_POST['cf_locality'],
       				'state' 		=> $_POST['cf_administrative_area_level_1'],
       				'zipcode' 		=> $_POST['cf_postal_code'],
       				'country' 		=> $_POST['cf_country'],
       				'lat' 			=> $_POST['cf_lat'],
       				'long' 			=> $_POST['cf_lng'],
       			)
       		);
   
       }
       add_action( 'wpuf_add_post_after_insert', 'add_location_info' );// JavaScript Document
       ```
   
 * I will try this and let u know!
    Thanks for the response.
 *  Thread Starter [writegnj](https://wordpress.org/support/users/writegnj/)
 * (@writegnj)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/#post-4522171)
 * I was missing
    `global $wpdb;` before the insert line. it WORKS good. [@mainpart](https://wordpress.org/support/users/mainpart/)
   Thank you so much.
 *  Thread Starter [writegnj](https://wordpress.org/support/users/writegnj/)
 * (@writegnj)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/#post-4522172)
 * This got me to have more questions. lol so I see how to insert and replace data
   on database but I can’t figure it out how to delete data.
 * it does not seem like have action hook for post delete, so I was trying to add
   below into wpuf-dashboard.php right after `wp_delete_post( $_REQUEST['pid'] );`
 *     ```
       global $wpdb;
       $post_id = $post->ID;
       $wpdb->delete( $wpdb->prefix . 'places_locator', array( 'post_id' => $post_id )  );
       ```
   
 * Could u tell me what I;m doing wrong?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Add action hook function.’ is closed to new replies.

 * ![](https://ps.w.org/wp-user-frontend/assets/icon-256x256.gif?rev=2818776)
 * [User Frontend: AI Powered Frontend Posting, User Directory, Profile, Membership & User Registration](https://wordpress.org/plugins/wp-user-frontend/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-user-frontend/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-user-frontend/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-user-frontend/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-user-frontend/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-user-frontend/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [writegnj](https://wordpress.org/support/users/writegnj/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/add-action-hook-function/#post-4522172)
 * Status: not resolved