Form data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bruce Dickinson
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2009 6:26 pm

Form data

Post by Bruce Dickinson »

Hello,

Is it possible to access the "value" information of a form input type? for example:

Code: Select all

 
<input type="hidden" name="ID" [b]value="3059"[/b]>
 
I know I can access "name" with:

Code: Select all

 
$_POST['name']
 
But how can I access "value"? Is that part even submitted?

Thank you. :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Form data

Post by Luke »

You are actually mistaken. You can't access the name with $_POST['name']. You can access the value of your form element with $_POST['ID']. You use the name of the form input as the array key. For instance, if I have this form:

Code: Select all

<form method="post">
    <input type="hidden" name="action" value="dostuff">
</form>
Once the form was submitted, you could access the value of that input with $_POST['action']. Get it?
Bruce Dickinson
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2009 6:26 pm

Re: Form data

Post by Bruce Dickinson »

Hi Luke,

There seems to be a little misunderstanding here. I should have put $_POST['ID'] instead of 'name', that was a typo. :oops:

But I don't want to access the ID, I've already done that, I want to access the value part of it.


Basically, I've already got the $_POST['ID'], but how do I do the same for value? Let me give another example:

Code: Select all

 
<input type="hidden" name="ID" value="10">
 
I want to use PHP to also get that 10 out of the "value = 10" part of it. Is that possible? I can't seem to be able to find anything out about it.
Last edited by Bruce Dickinson on Sun Mar 01, 2009 9:17 pm, edited 1 time in total.
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: Form data

Post by semlar »

$_POST['name'] contains the value of the form item with that name.

Your input box happens to be named "ID".

From your example: $_POST['ID'] => 10

You can see the contents of the $_POST array by printing it to the page.

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
Bruce Dickinson
Forum Newbie
Posts: 5
Joined: Sat Feb 28, 2009 6:26 pm

Re: Form data

Post by Bruce Dickinson »

Well, that was a silly mistake to make!

I haven't had a lot of experience but that should have been an obvious one. :oops:

I was assuming the value of "name" was ID and the value of "value" was 10 and they were both used separately. Now I understand how this works.

Thanks guys!
Post Reply