Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Calling a string in a link

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #40291
    slb535
    Member

    Here’s my code. In case it isn’t obvious what I’m trying to do, I want to only show the image if there is info in the field. And the link around the image uses the info in the field. The mailto: is coming up blank. So I’m guessing/hoping I’m doing something wrong with the way I’m printing/calling it. I would greatly appreciate any help.

    if ( $email ) { ?>
    “>

    pmac627
    Participant

    Try this:

    $email = types_render_field (“email”);
    if (!empty($email)) {
    ?>
    “>http://php.net/manual/en/function.empty.php
    isset might work better for you.

    EDIT: Also, your $empty variable right after the mailto is missing a semicolon. ;)

    #111849
    slb535
    Member

    Thanks for looking at this.

    knocks it out of the HTML it’s in. So instead of an image wrapped in a URL, I get
    [email protected]"> IMAGE

    pmac627, your solution doesn’t work for me either. I still get a blank value for my string. And I’ve tested other fields, to make sure it isn’t just this field. I will look into isset though. Thanks for the recommendation.

    #111868
    pmac627
    Participant

    Perhaps try echo $email; instead? Good call, @traq. I can’t believe I missed that as well.

    Try to echo $email somewhere on the page to make sure that it actually contains a value.

    #111879
    Vermaas
    Participant

    This will do the trick:

    Don’t know why the markup of this is so shit. But copy it in your code and make it look more nice.

    ` // Get the e-mail variable
    $email = types_render_field (“email”);

    // Print out the e-mail variable, to make sure you’ve got one
    echo “

    " . print_r($email) . "

    “;

    // Check for an e-mail address
    if ( !empty($email) ) { ?>
    “>

    slb535
    Member

    Nope, I’ve tried echo before. It does the same thing as print — knocks it out of the href link and displays it on the page.

    And Vermaas, unless I’m missing something, yours is the same as pmac627 with just the print_r ($email) to test the content of the string. Am I getting that wrong?

    I’m hoping to have this site online for testing in a few days. Perhaps I can post a link then and get your thoughts.

    Again, thanks for trying.

    #112029
    slb535
    Member

    I figured it out! It had to do with the way the custom field had been created. When it was an “email field”, it gave me that big mess. When I made it just a single line text field, it was fine.

    Thank you all for your help. (Especially since I was missing that echo in addition to everything else.)

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Back End’ is closed to new topics and replies.