Reputation: 75
I'm passing some variables from one page form to another from AWeber. They provide Javascript to do this, but I'm trying to do it with PHP, because I don't know javascript. However, the variable names have spaces and () in them, which PHP doesn't like, so I'm trying to figure out how to get the variables to recognize.....
AWeber uses input field names such as "name (awf_first)" and "name (awf_last)", so my php is:
<?php
$email=$_GET['email'];
$awf_first=$_GET['name (awf_first)'];
$awf_last=$_GET['name (awf_last)']; ?>
but the first and last fields don't work - I assume because of the space and parens. I can't change them because that's what AWeber uses...is there a way to escape them or get them to work somehow?
Thanks!
Upvotes: 0
Views: 1422
Reputation: 50643
Try with:
$awf_first=$_GET['name_(awf_first)'];
$awf_last=$_GET['name_(awf_last)'];
As PHP transform the spaces for underscores in the variable names passed on the query string.
For the explanation about this PHP behaviour it's well explained in https://stackoverflow.com/a/283781/352672
Upvotes: 2
Reputation:
I did the opposite once (PHP to Javascript), but I'm pretty sure it would work too for Javascript to PHP. It wouldn't be the cleanest solution, AJAX is better in my opinion, but still, you can try this out.
First, you have a PHP file who is passed as a Javascript file with this line at the top of your PHP file.
<?php header('Content-type: text/javascript'); ?>
What I used to do is this (PHP to Javascript):
var javascriptVariable = <?php echo("lala") ?>;
but for you, it would be the opposite (Javascript to PHP):
<? $var = ?> javascriptVariable;
Let me know if it works.
Upvotes: 0