Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

taken on someone elses code and trying to get a clear understanding of just how the comments forms should work. they're being used as feedback for someones visit to the venue, so not as a comment on a post like normal wordpress installations.

the comments form looks custom, but i think its fairly standard and it definitely uses the standard wp-comments-post.php page to add them to the db.

            <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" name="commentform" id="commentform">
                <div class="left-column">
                <?php if ( is_user_logged_in() ) : ?>

                Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out &raquo;</a>

                <?php else : ?>

                <input value="Name" type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> />
                <input value="Email Address" type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> />
                <input style="display:none" type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" />

                <?php endif; ?>
                </div>

                <div class="right-column">
                    <label style="font-size:13px; margin-bottom:8px; float:left">Comment :</label>
                    <textarea style="float:left" name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea>
                    <a class="form-submit" href="javascript:document.commentform.submit();" value="Submit"><span class="button-left"></span><span class="button-middle">Submit</span><span class="button-right"></span></a>
                    <?php comment_id_fields(); ?>
                    <?php do_action('comment_form', $post->ID); ?>
                    <input type="hidden" name="comment_post_ID" value="<?php echo $post->ID; ?>" />
                </div>
            </form>

so user submits a comment, this hits the comments-post.php page which then redirects the user to a news item.

its the last bit i dont understand and it feels wrong. i would have thought it would go back to the submitting page, and display the "thanks for submitting..." message.

i know its possible to alter the redirect by amending the $location var in the following lines which are the last 3 of the wp-comments-post.php page.

$location = empty($_POST['redirect_to']) ? get_comment_link($comment_id) : $_POST['redirect_to'] . '#comment-' . $comment_id;
$location = apply_filters('comment_post_redirect', $location, $comment);

wp_safe_redirect( $location );[/code]

but the problem with that is you lose your info in POST and the thanks for submitting message never appears. it also feels like a hijack.

so whats the way to get this working right? is it to load the comment form with the right variable for the redirect and then get that into POST the usual way (by being inside the form?)?

if ive missed some glaringly obvious article on how to do this without reinventing the wheel please direct me to it.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you want to redirect the user to somewhere else after they submit a comment, then all you have to do is include a hidden input in your comment form with the name of "redirect_to" and the value of the URL you want to redirect them to. The lines of code you posted show that directly. No need to hack the core code.

share|improve this answer
    
thanks for the comment. i remember wondering if that was an option when i came across this, but its taken me a week to post this q. will go test that now. –  shofty Sep 24 '12 at 10:12
    
that did just what i needed it to, thanks for reminding me about it. it doesnt however seem to send back a POST response, so the code to thank the user never fires, any obvious way of making this happen? –  shofty Sep 24 '12 at 10:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.