WordPress.org

Ready to get started?Download WordPress

Forums

Print a URL passed variable on your WP Page? (19 posts)

  1. LesTexas60
    Member
    Posted 7 months ago #

    I know I am so close and missing something simple here. I have passed a variable from one WordPress page to another using:
    http://www.page1/?Les=333

    The variable and value is available when I get to the new page but I don't know how to simply print the variable value (333) on the page.

    Any suggestions would be appreciated.

  2. graphical_force
    Member
    Posted 7 months ago #

    Could you post any code that you have so we can take a look?

  3. LesTexas60
    Member
    Posted 7 months ago #

    That's the problem. I have accessed the URL variable through Gravity forms and the variable is {entry_url}SendTo
    that holds the value passed from one page to another. I am thinking I should be able to go to the page HTML Tab and simply add a type of Print variable code to get it to display on the page.
    Does that make sense? I've looked all over for various html code to print variables but nothing is working, the actual code shows on the page rather than the value of the variable.

  4. graphical_force
    Member
    Posted 7 months ago #

    So if your trying to access the variable via Gravity Forms, you need to post there to get support. I have a developers account there and they are great about supporting these issues. This forum does not support premium plugins or themes since we cannot download the code without paying first to look at it.

  5. LesTexas60
    Member
    Posted 7 months ago #

    Thanks graphical. I am trying to print this variable above the Gravity Form, not within it. My first goal was to pull the variable into the Gravity form and display it. That worked but I could not set the Field to "Read Only" because Gravity forms doesn't have that option. My next step was to show the field above the form in a Print type statement. I know it's convoluted but it seemed to be a workable solution. I am not that great at HTML but I can get most simple code accomplished.
    I appreciate your comments.

  6. graphical_force
    Member
    Posted 7 months ago #

    Ok, so really gravity forms has nothing to do with this. Fine. So you are saying that you want to get the value that is passed in a url? In your example http://www.page1/?Les=333 you want to get Less=333 and store it in a php variable correct? From there you should be able to do whatever you want with it.

  7. LesTexas60
    Member
    Posted 7 months ago #

    Yes, Les is the variable and 333 is the value of the variable. All I want to do is print 333 above the form in the content portion of the WP page.

    Obviously the value of "333" will change based on what page originated the call to this page.

    Thank you for your patience...

  8. graphical_force
    Member
    Posted 7 months ago #

    You can use GET to get the variable passed in the url. So you need to grab Les=333 and put that in a variable. From there you can manipulate it by breaking it up into Less and 333. Whatever you want to do at that point.

    This should help you: http://www.php.net/manual/en/reserved.variables.get.php

  9. LesTexas60
    Member
    Posted 7 months ago #

    Thanks Graphical.
    I entered both

    <?php
    echo 'Hello ' . htmlspecialchars($_GET["SendTo"]) . '!';
    ?>

    
    (To show the variable)
    
    <?php
     print_r($_GET);
     if($_GET["SendTo"] === "") echo "a is an empty string\n";
     if($_GET["SendTo"] === false) echo "a is false\n";
     if($_GET["SendTo"] === null) echo "a is null\n";
     if(isset($_GET["SendTo"])) echo "a is set\n";
     if(!empty($_GET["SendTo"])) echo "a is not empty";
    ?>
    

    (and this to show a possible error)

    Go to this page: http://nwihabitat.org/email-habitat-staff/
    select anyone to send an email to and it will take you to the next page and at the bottom you will see the results of the entered code. It just prints it out rather than executing the code.

  10. Andrew
    Forum Moderator
    Posted 7 months ago #

    Are you putting the PHP in the Visual/ Text editor?

  11. graphical_force
    Member
    Posted 7 months ago #

    I understand what you want to do, I'm just confused on what you code looks like exactly. So you are using the code on the page you are landing on correct?

    So if I go to http://www.page1/?Les=333 then the page that I land on uses the code to then get the url.

    This is a php question rather than a WordPress question. You should be able to find out with a google search like this: get variable from url php

  12. LesTexas60
    Member
    Posted 7 months ago #

    Andrew, yes I am putting the code in the "Text" tab

  13. LesTexas60
    Member
    Posted 7 months ago #

    Graphical. When you choose a staff member on page one you are taken to page two, and a variable is passed through the URL telling page 2 what staff member you chose. It then auto populates the Gravity Form To Email variable so it knows where to send the form. If you look at the top of the form you will see the staff members name was populated correctly. The issue is, it's not a read only field. If someone typed over the Members name the email would not be sent correctly. Once I figure out how to display the URL variable on this page, I will set the Gravity Form variable to "Private" so it can't be seen and over written.

    Hope that clarifies...

  14. graphical_force
    Member
    Posted 7 months ago #

    You can't run php in the text tab. It has to be in the code of the page/page template. You may find a plugin that allows you to do that.

  15. LesTexas60
    Member
    Posted 7 months ago #

    Thanks Graphical, as I mentioned web code is not my strong point. Is this where a Short Code might work? I am an old coder from way back but I prefer WYSIWYG type wed design like Joomla or WordPress.
    COBOL was my first language...

  16. graphical_force
    Member
    Posted 7 months ago #

    There may be a plugin to assist you with this but I don't know of any. I DO know that you can do it in the code so that is what I can offer.

  17. LesTexas60
    Member
    Posted 7 months ago #

    Thanks Graphical... I thought this was going to be an easier way of doing this. I may go back and see about trying to set the Gravity Form field to no edit. I find it hard to believe that Gravity Forms doesn't have an option to make a field "Display Only". Seems obvious. I will change forums and head in that direction.
    Thanks for all your help, Even I didn't finish my task, I did learn some new things today.

  18. LesTexas60
    Member
    Posted 7 months ago #

    Yea, just to let anyone else know how to do this if they need to.
    Install Plugin "Insert PHP" then you just have to replace the standard PHP with Insert PHP replacements. It only took about 6 hours and lots of help from Graphical-Force.

    (Standard PHP statement)
    <?php
    echo 'Hello ' . htmlspecialchars($_GET["name"]) . '!';
    ?>

    (Change to)
    [insert_php]
    echo 'Attn:' . htmlspecialchars($_GET["Name"]) . '!';
    [/insert_php]

  19. graphical_force
    Member
    Posted 7 months ago #

    Glad you found a solution. :)

Reply

You must log in to post.

About this Topic

Tags

No tags yet.