Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-02-2011, 12:09 AM   PM User | #1
RWhit
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
RWhit is an unknown quantity at this point
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..
RWhit is offline   Reply With Quote
Old 09-02-2011, 04:02 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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>
Inigoesdr is offline   Reply With Quote
Users who have thanked Inigoesdr for this post:
RWhit (09-02-2011)
Old 09-02-2011, 06:49 PM   PM User | #3
RWhit
New to the CF scene

 
Join Date: Sep 2011
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
RWhit is an unknown quantity at this point
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..
RWhit is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:24 PM.


Advertisement
Log in to turn off these ads.