Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need Help with passing PHP database info to a Javascript src URL

    Hi all,

    I'm a newbie to coding in general (barely know enough to be dangerous), but I've created a company and decided to handle the integration myself. Now I realize I'm a bit over my head and can use a little help! I need to pass user info from my Wordpress database into a URL, then place that URL into an external Javascript link. I may not be explaining this well, so let me attempt to show my dilemma.

    Here's the PHP code to pull a users email address from my wordpress database:
    Code:
      <?php function getemail() {
    $current_user = wp_get_current_user();
       
        echo $current_user->user_email;
        }
    	?>
    This code calls the function and prints the email address:
    Code:
    <?php
    $func = 'getemail';
    $func(); ?>
    Now this is where I'm stuck, how would I get this email address to populate after the 'clientid=' portion of the following JavaScript src field? Would I have to rewrite with $_GET and create a custom url, then pass it on some other way?

    Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=company'> </script>
    Any help would be GREATLY appreciated. I really need to populate these fields automatically or I can't tell which customer I'm chatting with or track their individual tickets. Thank you in advance!
    Last edited by RWhit; 09-02-2011 at 12:12 AM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by RWhit View Post
    This code calls the function and prints the email address:
    Code:
    <?php
    $func = 'getemail';
    $func(); ?>
    You shouldn't need to assign it to a variable like that. Just call getemail().
    Quote Originally Posted by RWhit View Post
    Now this is where I'm stuck, how would I get this email address to populate after the 'clientid=' portion of the following JavaScript src field? Would I have to rewrite with $_GET and create a custom url, then pass it on some other way?

    Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=company'> </script>
    It depends on the context you are outputting that line in. Assuming it's in an HTML block in a PHP page you could do something like this:
    PHP Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=<?php getemail(); ?>'> </script>

  • Users who have thanked Inigoesdr for this post:

    RWhit (09-02-2011)

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hey Inigo! Thanks for your response, you are correct in assuming that it is an HTML link. I've actually figured it out and am posting what I came up with here in case anyone else needs help parsing info into an HTML link between languages. I'm pretty sure that the code is sloppy, because I am a beginner, but it works! I'm still assigning the function to a variable only because for some reason typing getuserinfo() to call it wasn't working on my Wordpress site. Could be a conflict with an existing plug-in or even PEBKAC to be honest.

    Code:
    <?php function getuserinfo() {
    $current_user = wp_get_current_user();
    $Email = $current_user->user_email;
    $UserL = $current_user->user_login;
    $UserFN = $current_user->user_firstname;
    $UserLN = $current_user->user_firstname;
    //Build variable for NTR button
    $NTR_code = "<script language='JavaScript' src='[edited link]p=1;ref=$Email;description;ref=$UserFN&ref=$UserLN;company&ref=name&clientid=ref=$UserL'> </script>";
        
    
    print $NTR_code;
        }
    $func = 'getuserinfo';
    $func();?>
    Any constructive criticism is welcome. Enjoy!
    Last edited by RWhit; 09-02-2011 at 06:54 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •