Styles2304 Posted November 20, 2008 Share Posted November 20, 2008 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 More sharing options...
genericnumber1 Posted November 20, 2008 Share Posted November 20, 2008 Your code is completely wrong, you have html inside of php tags? Only php code should belong inside of <?php ?> Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-693970 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 . . . That's why I took the time to note that it was within an EOD block. Either way, has nothing to do with the question which, restated, is how do I access posted variables when the variables I need to access are dynamic? Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-693974 Share on other sites More sharing options...
btherl Posted November 20, 2008 Share Posted November 20, 2008 You can try {$_POST[$BlockName.$Title]} Those {} will allow you to do a lot of stuff that otherwise wouldn't work inside a string or "EOD" block (the technical but still rather odd name for an EOD block is "heredoc"). Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-693982 Share on other sites More sharing options...
genericnumber1 Posted November 20, 2008 Share Posted November 20, 2008 Yeah, sorry, I've never heard it referred to as an "EOD" block, only heredoc. Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-693990 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 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. Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-693993 Share on other sites More sharing options...
btherl Posted November 20, 2008 Share Posted November 20, 2008 If that's the case, try this: print <<<EOD {$_POST[$BlockName . '_' . $FColor]} EOD; Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-694004 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 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? Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-694006 Share on other sites More sharing options...
Styles2304 Posted November 20, 2008 Author Share Posted November 20, 2008 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. Link to comment https://forums.phpfreaks.com/topic/133424-solved-_postvariable-is-it-possible/#findComment-694010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.