/    Sign up×
Community /Pin to ProfileBookmark

$_POST to Array

Hi,

I have a form that has 3 radio buttons.
Now I want to associate these with values in array.

So I have values like ‘1’,’2′ and ‘3’.

‘One is good’,’two is better’,’three is best’.

Please help!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleFeb 12.2008 — $_POST is an array. I don't understand what the question is.
Copy linkTweet thisAlerts:
@invisionauthorFeb 12.2008 — Sorry.

I have :

[code=php]echo '<input type="radio" name="proof" value="1" selected/>Please ammend and reproof<br />
<input type="radio" name="proof" value="2" />Please ammend and print<br />
<input type="radio" name="proof" value="3" />Approve and Print</p><br />';[/code]


And when submitted I want the value of '1' to be equal to 'Please ammend and reproof' and store that val in a variable.

Thanks.
Copy linkTweet thisAlerts:
@invisionauthorFeb 12.2008 — Just to ask again, basically I need it so if the user selects and submits radio button 1, that a variable, say, $proofcomment will store the string value = "Please ammend and reproof"

Can anyone please help with this?


Thanks!
Copy linkTweet thisAlerts:
@felgallFeb 13.2008 — So set the values to what you want them to be instead of 1, 2, and 3.
Copy linkTweet thisAlerts:
@jasonahouleFeb 13.2008 — or use an array
[code=php]
$proofEnum = array("Please ammend and reproof", "Please ammend and print", "Approve and Print");
$proofText = $proofEnum[$_POST['proof']];
[/code]

Or you can create an enumeration (sort of).
[code=php]
...
class ProofEnum {
public const REPROOF = 1;
public const AMEND = 2;
public const APPROVE = 3;
}
...
switch($_POST['proof'])
{
case ProofEnum::REPROOF:
// do whatever you need to for "Please ammend and reproof"
break;
case ProofEnum::AMEND:
// do whatever you need to for "Please ammend and print"
break;
case ProofEnum::APPROVE:
// do whatever you need to for "Approve and Print"
break;
default:
// the user didn't choose any of these
}
[/code]

It all depends on what you are tying to do.
Copy linkTweet thisAlerts:
@MrCoderFeb 13.2008 — 
Or you can create an enumeration [B](sort of)[/B].[/QUOTE]


lol, first time I have ever seen that done with PHP.

Well played ?

Any other weird and wonderful ways of doing it?
Copy linkTweet thisAlerts:
@jasonahouleFeb 13.2008 — Yeah, it isn't really an enumeration but you have to work with what the language gives you. Like I said, I have no idea what he is trying to do.

I have actually created an enumeration class that has most of the functionality of an enumeration in say C# or Java. It is really quite useful.
×

Success!

Help @invision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...