Facebook app form that reconncts to user Access_token And Userid post to DB

Hello,

Have a question that i hope some one can help me answer.

I have started creating a facebook app that will translate lovepoems.

The problem im having is that facebook redirects everything wrong, which makes my life a living hell. So what i thought is it’s possible to while submitting the form and the user gets redirected to the facebook allow app page, wait with submitting the form or maybe bring the post id with me and then post the content to the db liked to the post from a different page.

simply so i don’t have to make the accept form and then go to the actual content?

So I’m using Wordpress as default CMS system if that helps.

This is the code.

[php]<?php
/*
Template Name: Febuary Love testing app
*/
?>

<?php add_filter('fb_php_sdk_load','your_filter'); function your_filter($array) { $array[] = '2.1.2'; //exact version number you need return $array; } $facebook = new Facebook(array( 'appId' => '179200268852090', 'secret' => '3b62bc6b207e4038aa56a28bfc5ed368', 'cookie' => true, )); $session = $facebook->getUser(); if (!empty($session)) { try{ $user = $facebook->getUser(); $user = $facebook->api('/me'); } catch (Exception $e){ } if (!empty($user)) { } else die ("An error occured"); } else{ $loginUrl = $facebook->getLoginUrl(array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => 'offline_access, publish_stream' )); echo "Click to add the Copypanther Facebook application"; } ?> <?php $user = $facebook->getUser(); if($user){ $access_token = $facebook->getAccessToken(); } ?> <?php if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") { // Do some minor form validation to make sure there is content if (isset ($_POST['title'])) { $title = $_POST['title']; } else { echo 'Please enter the Poem name'; } if (isset ($_POST['description'])) { $description = $_POST['description']; } else { echo 'Please enter some notes'; } $tags = $_POST['post_tags']; $access_token = $_POST['access_token']; $user = $_POST['user']; // ADD THE FORM INPUT TO $new_post ARRAY $new_post = array( 'post_title' => $title, 'post_content' => $description, 'post_category' => array($_POST['cat']), // Usable for custom taxonomies too 'tags_input' => array($tags), 'post_status' => 'draft', // Choose: publish, preview, future, draft, etc. 'post_type' => 'post', //'post',page' or use a custom post type if you want to 'access_token' => $access_token, 'user' => $user, ); //SAVE THE POST $pid = wp_insert_post($new_post); add_post_meta($pid, 'access_token', $access_token, true); add_post_meta($pid, 'user', $user, true); //SET OUR TAGS UP PROPERLY wp_set_post_tags($pid, $_POST['post_tags']); //REDIRECT TO THE NEW POST ON SAVE $link = get_permalink( $pid ); wp_redirect('http://www.ngee.se'); } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM //POST THE POST YO do_action('wp_insert_post', 'wp_insert_post'); get_header(); ?> <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
                <div class="form-content">
                    <?php the_content(); ?>

					<!-- WINE RATING FORM -->

					<div class="wpcf7">
						<h2>Share some February Love!</h2>
						<p>Although the 14th of February might and should be dedicated to your loved one, we think that friends, bosses and coworkers deserve some affection, too. So between the 1st and 13th of February we will translate a poem or message from you to them <em>for free</em></p>
					<form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
						<!-- post name -->
						<fieldset name="name">
							<label for="title">Love poem name:</label>
							<input type="text" id="title" value="" tabindex="5" name="title" />
						</fieldset>

						<!-- post Category -->
						<fieldset class="category">
							<label for="cat">Translate to:</label>
							<?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
						</fieldset>

						<!-- post Content -->
						<fieldset class="content">
							<label for="description">Love poem:</label>
							<textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
						</fieldset>

						<!-- post tags -->
						<fieldset class="tags">
							<label for="post_tags">Keywords (comma separated):</label>
							<input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
				
						<fieldset class="submit">
								<input type=button value="Send" value="Send" tabindex="40" id="submit" name="submit" onclick="verify();">
						</fieldset>
						
						<fieldset class="access_token">
							<label for="access_token"></label>
							<input type="text" value="<?php echo $access_token;?>" id="access_token" name="access_token"/>
						</feildset>
						
						<fieldset class="user">
							<label for="user"></label>
							<input type="text" value="<?php echo $user;?>" id="user" name="user" />
						</feildset>
													
						<input type="hidden" name="action" value="new_post" />
						<?php wp_nonce_field( 'new-post' ); ?>
					</form>
					</div> <!-- END WPCF7 -->
					
                    <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                    <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                </div><!-- .entry-content -->
            </div><!-- #post-## --> 
<?php endwhile; // end of the loop. ?> <?php get_footer(); ?>

[/php]

Any one have any idea about how i can solve this problem ?

Answers most appreciated!

Best Regards
GrundeLL

Sponsor our Newsletter | Privacy Policy | Terms of Service