WordPress.org

Forums

Redirects (4 posts)

  1. lvneditor
    Member
    Posted 5 years ago #

    I am doing a site for someone else and they are planning on having presentations that they have given on a page(s). They would like to have the presentations listed as links on a "Presentations" page. These links would then take the visitor over to a form page, which would be used to harvest the visitor's information. I'm OK w/ all of this.

    However, they would like to redirect visitors to a specific presentation (the one associated with the link that they originally clicked) after they have submitted the form. Is this possible? Without a ton of programming? Does every presentation link have to have a separate form page that would then redirect to the specific presentation?

    I am really at loss as to how to go about this and would appreciate any help that I might be able to get. Thanks!

  2. Simon Fairbairn
    Member
    Posted 5 years ago #

    You could have the links pass over the id of the presentation on a GET variable, then take that GET variable and pass it through POST on submission of the form, then have the form processing page redirect them to the correct presentation page.

    Presentation links page:

    <a href='presentation/form/?id=1'>Presentation 1</a>
    <a href='presentation/form/?id=2'>Presentation 2</a>

    Form page:

    <?php
    $presentationID = $_GET['id'];
    ?>
    
    <form action='formProcessor.php' method='post'>
    // FORM CODE GOES HERE
    
    <input type='hidden' value='<?php echo $presentationID; ?>' name='presentationID' />
    </form>

    Finally, formProcessor.php

    <?php
    // PROCESS FORM HERE - NO OUTPUT TO SCREEN AT ALL (NOT EVEN WHITE SPACE)
    $redirectPage = $_POST['presentationID'];
    
    if ($redirectPage == '1') {
     $location = get_option('siteurl') . '/presentation1/'
    } elseif ($redirectPage == '2') {
     $location = get_option('siteurl') . '/presentation2/'
    } ...
    
    wp_redirect($location);
    ?>

    Obviously this is just an example and you'd have to adapt it to your needs.

  3. lvneditor
    Member
    Posted 5 years ago #

    Simon,

    Greatly appreciated. Being a designer, not a programmer(obviously), I have a couple of questions.

    1. Am I correct in assuming that where you have:

    // PROCESS FORM HERE - NO OUTPUT TO SCREEN AT ALL (NOT EVEN WHITE SPACE)

    I would enter my form processing script and remove the slashes?

    2. Is 'siteurl' passed or provided by me?

    3. Am I also correct in assuming that I continue with elseif arguments until it matches the number of presentations?

    4. I am also assuming that as the presentations vary on the Presentations links page, the formProcessor.php file will need to be updated to reflect those changes. Correct?

    Sorry for all the questions. I just haven't taken the time to take a PHP class and learn the language. It's on my to-do list for this upcoming winter!

    Thanks for all of your assistance on this.

  4. Simon Fairbairn
    Member
    Posted 5 years ago #

    No worries. As a bit of a disclaimer, this code was only supposed to point you in the right direction rather than be a complete solution. There are quite a few problems with it if you use it exactly as is.

    But in answer to your questions:

    1. Yeah, if you have one. You have to be ultra careful that there is no white space anywhere within your script. If you get an error saying "headers already sent", then you know that you're outputting to screen somewhere. All the code has to be tightly packed in between the <?php and ?> tags. No space either side.

    2. The get_option('site_url') is a built in WordPress function that simply returns the entire url of your site. Copy as is and change the "/presentation1/" to wherever your presentation thing is located.

    3. Yep. As many as you need.

    4. It currently would. Given that this was all off the top of my head, it's probably not the cleanest solution. If the client is likely to want to add more presentations, or change them often, then you're going to need a stronger solution.

    Si

Topic Closed

This topic has been closed to new replies.

About this Topic