Jump to content

<span> & php


tommyinnn

Recommended Posts

Hi guys, can someone please help me understand why

 

this works

 

<? echo "<span id=phone_numberDISP></span>

 

but this won't

 

<a href="http://mywebsite.com?btn=<? echo "<span id=phone_numberDISP></span>"; ?>" target="_blank" > CI </a>

 

The first displays the phone number fine, but when I wrap it in a <a> tag, it won't display

 

thanks for any help any1 can give!

 

Link to comment
Share on other sites

You also don't want to put the SPAN in there.  Putting an html element into a query string is a bad idea.  And yeah, you will want to url_encode it as well (that way spaces and such won't break).

 

I think a lot of people have a hard time understanding spans...a span is literally nothing.  It's a way to seperate some content so that you can access it via javascript or css.  You never, ever, ever want to put an html element into a query string. 

Link to comment
Share on other sites

Thanks, but I'm trying to pass the phone number in the url -that code just displays the phone #, rather than pass it

 

here's a better way to show

 

<a href="http://mywebsite.com?phone=<? echo "<span id=phone_numberDISP></span>"; ?>" target="_blank" > CLICK HERE </a>

 

this is for a PBX app - vicicdial

 

As nafetski stated, you're outputting your span tag inside of your A tag's href attribute.  If you look at the output HTML, you'll see the problem.  Essentially what you're outputting is this:

<a href="http://mywebsite.com?phone=<span id=phone_numberDISP></span>" target="_blank" >CLICK HERE</a>

Maybe what you want to display is:

<a href="http://mywebsite.com?phone=XXXXXXXXXX" target="_blank" >CLICK HERE</a>

 

Also, you will want to url_encode your variable, so that it doesn't potentially further wreck your HTML.

Link to comment
Share on other sites

Thanks for all your help and tips guys, I've Googled url_encode trying to understand it, but am still unable to figure it out - it's crazy I'm not able to pass a 10 digit variable!!

Even tried to assign <span id=phone_numberDISP></span> a regular php variable ,

like <? $var="<span id=phone_numberDISP></span>": ?>

Link to comment
Share on other sites

Thanks for all your help and tips guys, I've Googled url_encode trying to understand it, but am still unable to figure it out - it's crazy I'm not able to pass a 10 digit variable!!

Even tried to assign <span id=phone_numberDISP></span> a regular php variable ,

like <? $var="<span id=phone_numberDISP></span>": ?>

 

In your example, where are you using this ten digit variable?  I see you only assigning an empty span to a variable.  Where would you insert the ten digits?

 

urlencode just encodes things in such a way that they won't interfere with the rest of your page.  For example, if one of your parameter's value had an ampersand or quotes, it might ruin your intended result (and also leave you open to some potentially nasty client-side exploits.)  urlencode transforms these characters into something that the web server can still read, as intended, but won't interfere with your HTML code.

Link to comment
Share on other sites

Well the code wouldn't have the variable in it,

 

This is the working code

 

<? echo "<span id=phone_numberDISP></span>"; ?>

 

The file I'm working on is very big, and although it is php - it's not really what I'm used to

 

If any1 wants to take a look at it, I've attached the file

The code in question is on line #8838

 

[attachment deleted by admin]

Link to comment
Share on other sites

ok I have to ask.

 

Why are you passing "<span id=phone_numberDISP></span>" as a variable??

 

if you want to just pass a ten digit phone number why are you passing that span tag?

 

if you really need to pass it then use this:

<a href="http://mywebsite.com?phone=<? echo url_encode("<span id=phone_numberDISP></span>"); ?>" target="_blank" > CLICK HERE </a>

 

then use

$phone = url_decode($_GET['phone']);

to decode it.

 

Link to comment
Share on other sites

Well the code wouldn't have the variable in it,

 

This is the working code

 

<? echo "<span id=phone_numberDISP></span>"; ?>

 

The file I'm working on is very big, and although it is php - it's not really what I'm used to

 

If any1 wants to take a look at it, I've attached the file

The code in question is on line #8838

 

Wow.  I do not envy you.

 

Looking through that code, it seems just as likely that JavaScript is the culprit.  I would actually recommend that you start there.  Make sure that everything is coming into your JavaScript, as expected.  From what I can see, it doesn't look like PHP is filling that value in, at all.  JavaScript is filling that empty span with values it's retrieving from an XML document.

Link to comment
Share on other sites

I dont even understand why this is a question? Why are you trying to put span into a tag property?

 

Tell me what you want the page to look like, and I'll give you the code. it SOUNDS like you want this:

 

<a href="http://mywebsite.com?btn=<? echo $phonenumber; ?>" target="_blank" ><span id=phone_numberDISP>CI</span></a>

Link to comment
Share on other sites

ksugihara - thanks, but that was the first thing I tried. That's what I was wanting to do - seems simple enough but I think fr34k is right, it's a javascript issue - here is a screenshot of what it looks like...

 

I know some of you are curious so I've uploaded a screenshot of this (had to block out some client info)

see the link "check" - that's the link I made to pass the phone number to another web form to verify the number against a second DB

I do thank you so much for your help!

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

I disagree about where the issue lies. Does span happen to have any properties in the CSS file? I believe this is a CSS issue, not a javascript. Infact, I cant even see where javascript comes into play....

 

If you download his file and look at it, you can see that PHP never puts anything into the span that he's referencing.  The span is filled via JavaScript.  The stated problem is that the value isn't showing up for him.  That's why I believe it is just as likely to be a JavaScript issue.

Link to comment
Share on other sites

Ahhh alright. why populate the link w/ javascript? why not populate it with php? it seems like populating w/ javascript would not be so great.

 

I think it's supposed to be an AJAX application, but it's massive (~9,000 lines), so I didn't give it a thorough looking over.

Link to comment
Share on other sites

LOL - yes, it is hugh! As you guys can tell, I am not a php expert, but passing simple variables is the basics, while VIciDial is a amazing script - it is kinda hard for me to understand many parts of it - It must be installed on a dedicated server - or VPS (I'm running it on Linux) - not your average php script at all.

There is no css file either, and for some reason, if I try and copy/paste that single line of working code on the line below it - the entire app fails. I'm not giving up - may be for the day but I am gonna work on this in the morning some more - I can't let it beat me! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.