Page 1 of 1
Form data
Posted: Sun Mar 01, 2009 6:53 pm
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:
But how can I access "value"? Is that part even submitted?
Thank you.

Re: Form data
Posted: Sun Mar 01, 2009 8:44 pm
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?
Re: Form data
Posted: Sun Mar 01, 2009 9:15 pm
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.
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.
Re: Form data
Posted: Sun Mar 01, 2009 9:17 pm
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>';
Re: Form data
Posted: Sun Mar 01, 2009 9:39 pm
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.
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!