Click to See Complete Forum and Search --> : PHP, convert value of variable into string.


Andrzej
September 21st, 2010, 07:06 AM
Hallo,

I can not manage some task


$field_name = "surname";

/* then I need to put this value to the $_POST array
something like this */

$var = $_POST[$field_name] ;

/* I tried like this but it doesn't work
$var = $_POST['\''.$field_name.'\'']);



could anybody write me how I can manage when the 'field_name' value is changed dynamicly

Thanks in advance

PeejAvery
September 21st, 2010, 12:52 PM
$_GET and $_POST are read only set by the data returned in a form or through AJAX.

Andrzej
September 23rd, 2010, 11:57 AM
so it means that there is no way to do it,
Am I right ?

PeejAvery
September 23rd, 2010, 01:28 PM
Not what you are describing. What exactly are you wanting to do?

Andrzej
September 23rd, 2010, 01:44 PM
I hve solved it but in a other way, it means that I put in my Form the field with the fixed name. But I still thin if it is possible

what I wanted to do:
my php code creates a FORM where the field_name depends on some condition let say that on Monday the filed name must be 'Mo' and on the Tusday the filed name must be 'Tu' and so on ..., it is just a stupid example but I I theoreticaly wonder how it could be implemented in php code.

If you could suggest me some way it would be nice.

PeejAvery
September 23rd, 2010, 02:47 PM
I'm sorry, but you're still not explaining yourself clearly. Why does it have to come from the form content?

laserlight
September 23rd, 2010, 03:21 PM
what I wanted to do:
my php code creates a FORM where the field_name depends on some condition let say that on Monday the filed name must be 'Mo' and on the Tusday the filed name must be 'Tu' and so on ..., it is just a stupid example but I I theoreticaly wonder how it could be implemented in php code.

If you could suggest me some way it would be nice.
In that case you would access $_POST[$field_name], as per your first post. The value of $field_name would be exactly the same as that used to create the form.

Andrzej
September 23rd, 2010, 03:26 PM
sorry, maybe my english is not good enough

for instance:

$field_name = GetFieldName();


$HTML .= '<form method="post" name=".myform" action="'.$this->ScriptFileName.'">';

//...

$HTM> .= "<input type=text name=" . $field_name . " value=" . $val . "</td>"


// then I need to get value typed by a user
$test = $_POST=['$filed_name']; // <= ofcourse it is wrong, but how it should be ...

PeejAvery
September 23rd, 2010, 05:15 PM
Get rid of the single quotes from the $_POST variable.

Andrzej
September 24th, 2010, 02:13 AM
Thank you
it works, thank you that you was patient with me.