0

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!

4
  • Try using $_REQUEST. The spaces and parentheses should not be a problem. Commented Oct 31, 2012 at 19:07
  • Could you paste the javascript they provided for doing this Commented Oct 31, 2012 at 19:09
  • the title and the question does not match.... Commented Oct 31, 2012 at 19:12
  • print_r($_REQUEST) will show all variables you're getting from that page Commented Oct 31, 2012 at 19:16

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Nice, I knew about the dots but didn't know about the spaces
Yes, these are some of PHP quirks.
@kgarrett I'm glad this worked for you, also remember to accept answer :-)
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.