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
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.

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.