WordPress.org

Ready to get started?Download WordPress

Forums

Carry the post title through to the contact page (8 posts)

  1. denzel2364
    Member
    Posted 3 years ago #

    Hi all,

    I want to create an 'apply' button that when pressed redirects to the contact page but then the title of this page is also carried forward.

    Any ideas?

  2. forunner
    Member
    Posted 3 years ago #

    maybe something like that in your loop

    <a href="link_to_the_contact.php?title=<?php the_title(); ?>contact</a>"
    Your title will be in the variable $_GET['title']

  3. denzel2364
    Member
    Posted 3 years ago #

    Fantastic, worked a treat.

    Further thoughts, i need this to be sent with the contact form. I could display the full URL to give a clue to where the user has come from. Or do you have a better idea?

    p.s. Thank you

  4. forunner
    Member
    Posted 3 years ago #

    I think you can have the uri of the previous page with
    $_SERVER["HTTP_REFERER"]

  5. denzel2364
    Member
    Posted 3 years ago #

    unfortunately not :-(

  6. forunner
    Member
    Posted 3 years ago #

    o_O
    try to put this in a page
    echo $_SERVER["HTTP_REFERER"];
    it should display the uri of the previous page !
    (if you come from a previous page, and don't type the uri directly)

  7. denzel2364
    Member
    Posted 3 years ago #

    ;-) Thank my friend.

    No chance of pulling the title aswell? :-o

  8. forunner
    Member
    Posted 3 years ago #

    you can use sessions to do this

    first you have to start the session in the beginning on each of your pages
    <?php session_start(); ?>

    in your loop, if there is a title, you have to put it into a session variable

    <?php if(isset(the_title())){
    $_SESSION['title'] = the_title();
    } ?>

    you can display it using an echo on the other pages
    <?php echo $_SESSION['title']; ?>

    warning : each time you go on the line
    $_SESSION['title'] = the_title();
    you will replace the value of the variable

    so you will have to use it before to come into the loop or to put it into a new variable in the beginning of your page
    <?php if(isset($_SESSION['title'])){$last_title = $_SESSION['title'];}?>

    hope you will understand everything (if my english seems weird, it's because I'm french =p)

    I've not try the code, maybe it's not working =S ! but I think you can find tuto about php sessions everywhere

Topic Closed

This topic has been closed to new replies.

About this Topic