using $wpdb to insert a form into a post

In the success part of your code, you can build an array representing a post, and use wp_insert_post as such :

Example

 $mypost = array(
      'post_title' => 'My Title',
      'post_type' => 'page'
      //... add other fields according to your form
 );

 $mypost_id = wp_insert_post( $mypost ); //Returns new post id on success

Any field you don’t specify will be filled by WordPress automatically.

EDIT

For custom fields, see add_post_meta :

 $mypost_id = wp_insert_post( $mypost ); //SEE ABOVE
 $meta_key = 'your-new-field-name';
 $meta_value="your-form-value";
 $unique = true; // or false     

 add_post_meta( $mypost_id, $meta_key, $value, $unique );

Source : wp_insert_post