wordpress - Passing Form Variables Between If Statement -
i'm working on front end submission page wordpress works in number of steps.
so i've got form on page , it's gathering data on few stages , posting after each stage.
i can fine using get, don't want variables viewable in url because easy people edit other posts on blog did not write.
how go passing post id stage stage using method? there better method out there multiple page forms?
as can see below, need pass post id between setup step , step 1 somehow dont want in url get.
update:
okay, seems step confirm the stage completed in if else statement loosing post , session variables, have changed displays form hidden inputs instead of continue link request. updated pastebin - http://pastebin.com/lphrhwre
here code using: http://pastebin.com/8b4qmnrm
php
<?php if(isset($_get['step'])){ $step = $_get['step']; if ($step == "setup"){ $setup = ""; $step_one =""; if(isset($_post['submit'])){ $guide_title = trim($_post['guide_title']); if($guide_title != "" ){ $post = array( 'post_title' => $guide_title, ); $post_id = wp_insert_post( $post, $wp_error ); $stage_complete = true; } else { $message = "please complete required fields."; } } else { $guide_title = ""; $stage_complete = false; } } else if($step == "one"){ $setup ="c"; $step_one = ""; if(isset($_post['submit'])){ $guide_new_title = trim($_post['guide_new_title']); if($guide_new_title != ""){ $my_post = array(); $my_post['id'] = $guide_id; $my_post['post_title'] = $guide_new_title; wp_update_post( $my_post ); $stage_complete = true; } else { $message = "please complete required fields."; } } else { $guide_title = ""; $stage_complete = false; } } } else { $step = "start"; } if(empty($message)){ $message = ""; } ?>
html
<?php if($step == "start"){ ?> <form action="<?php the_permalink() ?>?step=setup" method="post" class="formee"> <input class="button" type="submit" name="submit" value="go post setup"> </form> <?php } else if($step == "setup"){ ?> <?php echo $message; if($stage_complete == false){ ?> <form action="<?php the_permalink(); ?>?step=setup" method="post" class="formee"> <label>guide title <em class="formee-req">*</em></label> <input type="text" name="guide_title" required="required" value="<?php echo htmlentities($guide_title); ?>"> <input class="button" type="submit" name="submit" value="setup post"> </form> <?php } else { $step_one = "c" ?> <p>post has been setup.</p> <a href="<?php the_permalink(); ?>?step=one" class="button">continue step 1 →</a> <?php } ?> <?php } else if($step == "one"){ ?> <?php echo $message; if($stage_complete == false){ ?> <form action="<?php the_permalink(); ?>?step=one" method="post" class="formee"> <label>guide title <em class="formee-req">*</em></label> <input class="button" type="submit" name="submit" value="rename post title"> </form> <?php } else { $step_one = "c" ?> <p>post has been renamed.</p> <a href="index.php?step=finish" class="button">finished →</a> <?php } ?> <?php } ?>
just use hidden field in form so:
<input type="hidden" name="postid" value="<?= $theid ?>" />
and use post
rather get
form.
alternatively use session variable:
session_start(); $_session['postid'] = $theid; // access via $_session['postid']
Comments
Post a Comment