Search code examples
phpjavascriptvariablesescapingaweber

Inserting Javascript variable in php


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!


Solution

  • 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