I'm trying to retrieve the "custom Phone" value from a form where the variables are being passed through a URL and then retrieved using the PHP Get method.
Here is the URL with the pass through variables:
http://domain.com/redirect.php?custom%20phone=555-555-5555&email=jk%40blackdiamondacademy%2ecom&from=jk%40blackdiamondacademy%2ecom&listname=fgxpressusa&meta_adtracking=&meta_message=1&meta_required=name%2cemail%2ccustom%20Phone&name=Jordan&submit=Submit&submit.x=121&submit.y=27
Here is the code on my landing page that has the Get PHP code:
<script type="text/javascript">
var sale = PostAffTracker.createAction('lead');
sale.setOrderID('<?php echo $_GET['meta_message']; ?>');
sale.setProductID('<?php echo $_GET['unit']; ?>');
sale.setData1('<?php echo $_GET['name']; ?>');
sale.setData2('<?php echo $_GET['email']; ?>');
sale.setData3('<?php echo $_GET['custom%20phone']; ?>');
PostAffTracker.register();
</script>
The code retrieves the "name", and "email" but not the "custom%20phone". I tried putting 'custom phone' as the get value as well as 'custom+phone' and still it doesn't retrieve it.
The issue seems to be the space in the value from my web form ("custom Phone") that is being passed through the URL as "custom%20phone".
Any help would be greatly appreciated!
I just found the answer to my own question through trial and error.
The PHP GET method translates %20 as an underscore so I put:
<?php echo $_GET['custom_phone']; ?>
Works perfect!
Related
problem
i have two button "YES" and "NO". if user click YES then text input will appear with value set ex: value="$check['sum'];" but when user click No then text input will appear without value ex: value ="".
here is my code
<input id="test<?php echo $row['br_loc'];?>" value="<?php echo $value;?>" name="test" type="text" class="test" style="width:70px;display:none">
and jquery
$(document).ready(function(){
$("#Yes<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").show(1000);
});
$("#No<?php echo $row['br_loc'];?>").click(function(){
$("#test<?php echo $row['br_loc'];?>").hide(1000);
});
thanks you
Try using the disabled attribute:
$("#test<?php echo $row['br_loc'];?>").attr('disabled','disabled');
and
$("#test<?php echo $row['br_loc'];?>").removeAttr('disabled');
Try this:
$(document).ready(function(){
$("#YES").click(function(){
$("#test").show(); //value of input as set before. so, just show
}
$("#NO").click(function(){
$("#test").attr('value','').show(); //set value = '' , and show
}
});
Use binding function so that you provide your JS code with exact parameters. Code like yours should never be used.
Object ID or class should contain alphanumerical characters only, should not begin with number(s), and optionally, - or _ might be used. Avoid spaces or, as you've already shown yourself, using embedded PHP code which is highly unlikely to work in any further project of yours. It's also dangerous.
instead of this code $("#Yes<?php echo $row['br_loc'];?>")
try the following
$("#test<?php echo $row['br_loc'];?>").
Because you used id of button as "test<?php echo $row['br_loc'];?>". so only your click event not worked.
This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Closed 8 years ago.
There's probably something pretty easy here that I'm missing but I can't seem to figure it out.
I'm trying to pass a PHP variable "$session" from one PHP page to another PHP page using GET. The GET shows in the new URL but the value is not passed to the page so that I can retrieve it. Below is the relevant code.
On the main Index.php page.
<div class="mapgroup">
<table>
<tr>
<td></td>
<td id="refreshKML" ></td>
<?php echo "<td><a href='3D-Earth.php?session=$session' title='Full Size Google Earth' target='_blank' >Click here</a> for full size Google Earth</td>"; ?>
</tr>
</table>
<div id="map3d"></div>
</div>
The "$session" variable is passed to 3D-Earth.php using GET and the correct value shows in the URL. However, when I try to retrieve the variable with:
<?php
$session = $_GET["session"];
?>
and then try to create a javascript variable:
<script>
var session = <?php echo $session; ?>;
</script>
that I will use to concatenate the below string:
var href = 'http://localhost/satellites/' + session + '/master.kml';
nothing is being passed.
I appreciate any help anyone can provide. Thanks in advance.
Additionally, I've inserted the below code at the bottom of my 3D-Earth.php page to verify that the GET is being passed.
<div>
<table><p style='color:white;' >Hello " <?php echo $session; ?> " world!</p></table>
</div>
The result is an empty string that shows: Hello " " World! Anyone know what I might be doing wrong?
Try like this:
var session = '<?php echo $session; ?>';
I suggest stop using names like 'session' that might conflict with php reserved words. Maybe that's not the issue here, but avoids many other problems and confusions.
Also in javascript put the echo in quotes:
var session = '<?php echo $session; ?>';
You should put a single quotes around your variable like this
var session = '<?php echo $session; ?>';
As above answers say, you have to have single quotes around a php statement when you want to use it in javascript. So var session = 'php statement'; is the right way to go.
have you tried to put this code
<script>
var session = <?php echo $session; ?>;
</script>
under this code ??
<?php
$session = $_GET["session"];
?>
My problem is I have a php variable $ba with a value of 147 retrieved from a DB the below snipets of my code does not work, no image is shown. If I add $ba=147; before the fill_div call it works perfectly. I am stumped as to why it dos'nt work when $ba populated from the DB.
In both cases a check of the source code for the page shows the call being filled correctly fill_div("147");
<script type='text/javascript'>
function fill_div(ba)
{
document.getElementById("ba").innerHTML="<img src='admin/images/image.gif'/>";
}
</script>
<script>
fill_div("<? echo stripslashes($ba); ?>");
</script
<div id="<? echo $ba ?>" style="border:1px solid; width:120px; height:40px"></div>
You're passing the string literal"ba" to getElementById when you need to pass the variable ba
document.getElementById(ba).innerHTML="<img src='admin/images/image.gif'/>";
Also the stripslashes might not be a good idea if $ba has quotes in it, if $ba has a " in it will cause an error in your JavaScript if it is not escaped.
try ..
document.getElementById(ba).innerHTML
document.getElementById("ba")
should be
document.getElementById(ba)
Try changing your document.getElementById to:
document.getElementById(ba)
If it has quotes (as in your example code) "ba" is treated as a string, not a variable.
hi guys im trying to show and hide div according to mysql value but i couldnt do it can you help me what im doing wrong
here is my code thanks a lot for your ideas
var Value = <?php echo json_encode($valuek) ?>;
if (Value==1){
$('#show_hide').show();
}
else{
$('#show_hide').hide();
}
<?php
$valuek = $session->userinfo['vcc'];
?>
<div id="show_hide">
some code
</div>
<?php echo json_encode($valuek) ?>
will return a json string, instead try just using "echo"
<?php echo $valuek ?>
If all you are going for is a boolean value then there is simply no need for JSON.
Echo the value directly into the JavaScript. Remember to ensure you are passing a valid boolean value.
PHP code -
<?php
$showDiv = ($dbValue == 1? 'true' : 'false');
?>
JavaScript + PHP injection -
<script>
var value = '<?php echo $showDiv; ?>';
<script>
Don't forget to wrap the PHP injected value with quotes.
$valuek = $session->userinfo['vcc'];
I'm not sure if you have the code in this order in your php file, or just showed pieces of code in this order, but Should go BEFORE your js code. It has no value when js code is run.
To see what $valuek is, just echo it on top of the screen
<?php echo "<h1>$valuek</h1>" ?>.
Or just look at the source - at your js function, to see what is printed after 'var Value ='
That's the main thing really - to make sure that you getting what you expect from session.
And as been said, you don't need jason_encode, but you do need a semi-colon after echo command.
Also, I hope your jquery code is within $(document).ready function, not as is.
I tried this in my php site <a href=?command=value>click here</a>
And this to get the value :
if(isset($_POST['command'])){
$command=strip_tags($_GET['command']);
Does not seem to work.. Ps. The url have one this value also: ?lang=en_US
Use $_GET instead of $_POST. And also put double quotes around the value of href attribute.
Try this....this will work...
'click here'
this is to get the value from site:
<?php
if(isset($_REQUEST['command'])){
$command=($_GET['command']);
echo $command;
}
?>
the output: value
Note:Both the codes(php and html) are written in same page(company.php)
we can also write the php code in seperate page. Difference is,the 'isset' function is not needed there.And URL should change.
code will be the following.
'click here'
next_php_page.php code:
<?php
if($_REQUEST['command']){
$command=($_GET['command']);
echo $command;
}
?>