I’m trying to embed a variable in a block of code that I’m writing with php into a text area so it can be easily selected and copied to another web site. In production, the variables will be pulled from SESSION variables, but for you to be able to try this if you want by pasting it onto a page, I’ve hard wired the variable values.
The problem is that the php function is not picking up the variables. I’ve tried it with SESSION variables that exist before the page is written –no go. I’ve also tried loading variables into a form on the page and getting them through $_POST…no go.
What am I doing wrong here?
<?php session_start();
$fkey ="46";
$bleft = "0.86543";
$bpos = "tp";
$bcolor = "#eb9494";
$blabel = "CALL US";
echo "fkey: " . $fkey . "<br/>" ;
echo "bleft: " .$bleft . "<br/>" ;
echo "bpos: " .$bpos . "<br/>" ;
echo "bcolor: " .$bcolor . "<br/>" ;
echo "blabel: " .$blabel . "<br/>" ;
$updateGoTo = null;
switch ($thepos) {
case "tp":
$updateGoTo = "slideouttesttopDATA.php";
build_HTMLtp();
break;
case "bt":
$updateGoTo ="slideouttestbtmDATA.php";
build_HTMLbt();
break;
case "lt":
$updateGoTo = "slideouttestltDATA.php";
build_HTMLlt();
break;
case "rt":
$updateGoTo = "slideouttestrtDATA.php";
build_HTMLrt();
break;
}
?>
<html>
<body>
<form action="myform" method="post" enctype="application/x-www-form-urlencoded">
<?php
function build_HTMLtp() {
$myfield="<style>\n";
//style blocks
$myfield.=
"#slideouttop:{
position:absolute;
width:190px;height:187px;
top:-238px;
left:50%%;
}
.bizzopop,.bizzopopbtm{
background:url(http://dev.bizzocall.com/images/bcpopupwtrans.png);
background-repeat:no-repeat;
height:auto;
width:201px;
overflow:visible;
min-height:237px;
}
#clickmetop,#clickmebtm {
float:left;
clear:left;
height:20px;
width:80px;
}
#bcbuttontop,#bcbuttonbtm{
background-color:#000000;
position:relative;
cursor:pointer;
float:left;
clear:left;
left:0;
height:30px;
width:140px;
overflow:hidden;
}
.bcsquarebtntop,.bcsquarebtnbtm{
position:relative;
background-color:#000000;
float:left;
clear:left;
border:#ffFFFF;
width:15px;
height:15px;
border-width:2px;
border-style:solid;
left:6px;
top:5px;
}
.innersquarebtn{
background-color:#ffffff;
width:3px;
height:3px;
margin:auto;
margin-top:6px;
position:relative;
}
.btnlabeltxttop{
cursor:pointer;
display:inline;
overflow:visible;
height:40px;
width:100%%;
text-align:left;
text-indent:0;
left:0px;
position:relative;
float:left;
font-size:17px;
font-weight:bold;
color:#00FFFF;
top:-23px;
margin-left:32px;
}\n";
//special handling for variables
$myfield.=".bizzopop {background-color:" . $bcolor . ";}\n";
$myfield.=".btnlabeltxttop {color:". $bcolor .";}\n";
$myfield.="#slideouttop {
left:". 100*($bleft) ."%%;
display:". $tp .";
}
#clickmetop {
position:relative;
float:left;
clear:left;
height:20px;
width:80px;
z-index:1000;
}
</style>\n\n";
//now the html
$myfield.= "<div id=\"slideouttop\">
<div class=\"bizzopop\">
</div>
<div id=\"clickmetop\">
<div id=\"bcbuttontop\">
<div class=\"bcsquarebtntop\">
<div class=\"innersquarebtn\"></div>
</div>
</div>
<div class=\"btnlabeltxttop\">". $blabel ."</div>
</div>
</div>\n\n";
//jquery handlers
$myfield.="<script src=" . "\"http://" . "code.jquery.com/jquery-latest.js\"> </script>\"\n
$(function() {\n
$(\'#clickmetop\).toggle(function() {\n
$(this).parent().animate({marginTop:\'187px\'}, {queue:false, duration: 500});\n
}, function() {\n
$(this).parent().animate({marginTop:\'0px\'}, {queue:false, duration: 500});\n
});\n
});\n
</script>
";
printf ($myfield);
}
?>
<textarea name="myfield" cols="100" rows="30"><?php build_HTMLtp();?>
</textarea>
</form>
Global variables are not accessible inside functions unless you use global or access them via the $GLOBALS-array.