Search code examples
phpinputgetaweber

Accessing a user input field name that contains a space


I have a situation; I know that we can print data from query string like this;

 <?
 $firstname = $_GET['firstname'];
 echo $firstname;
 ?>

Issue is, I have a form with firstname and lastname fields with space in its name, like this;

<input type="text" class="text" name="name (awf_first)" value=""  onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="500" />
<input id="awf_field-72073394-last" class="text" type="text" name="name (awf_last)" value=""  onfocus=" if (this.value == '') { this.value = ''; }" onblur="if (this.value == '') { this.value='';} " tabindex="501" />

So in this situation I need to print first name and last name on the success page of form submit. What approach should I use?

I tired to do these two things but it didn't worked;

$firstname = $_GET['name%20(awf_first)'];
echo $firstname;

and the second approach

 $firstname = urldecode($_GET['name (awf_first)']);
 echo $firstname;

Please note, that its not possible to remove space from names of the input on form.

Thanks,


Solution

  • Instead of %20 just use _. Your code will be

    $firstname = urldecode($_GET['name_(awf_first)']);
    echo $firstname;