Jump to content

[SOLVED] $_POST[$variable] . . . is it possible?


Styles2304

Recommended Posts

The user chooses how many "blocks" they want and in doing so dynamically name the inputs in the blocks $BlockName.Title for example. In order to receive the posted data it would look something like $_POST[$BlockName . '.Title']; This doesn't seem to work however. Neither does asigning $BlockName . '.Title' to another variable and referencing it: $_POST[$BlockVariable];

 

Code:

<?php
Block Title:<br>
              <input type="text" name="$BlockName.Title" size="75" value="$Title"><P>
?>

 

This is within EOD.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/
Share on other sites

Well . . . this is interesting.

 

In the heredoc the input names are expressed as $BlockName.FColor but when I dump the $_POST variables, they're stored as $BlockName_FColor. That could be a problem . . . any ideas how to remedy the situation? Hell, if you can think of a way to join $BlockName and FColor without php thinking $BlockNameFColor is one big variable, I'm all ears.

I'm not handling the $_POST variables inside the heredoc so that part of it is actually good to go. It's just that php was substituting the "." with "_". So basically, my question as changed to:

 

Is there a way to join $BlockName with the word FColor so that the input name read $BlockNameFColor and PHP doesn't read that as one variable. FColor is not a variable, it's actually the word FColor.

 

Am I even making sense?

Ok well, I'm sure there's an easier way but what I ended up doing is just defining each variable as a word so Title became $WTitle which lets me put $BlockName$WTitle in the input field and then access it via $_POST[$BlockName . 'Title'];

 

Pretty sure this isn't the most efficient way but it works . . . thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.