Question about form input...

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
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Question about form input...

Post by Wolf_22 »

I have a form that basically has the following in it:

Code: Select all

echo "\t\t\t<input type=\"radio\" name=\"sols[0]\" value=\"" . $ops[$i] . "\"> " . $ops[$i] . "<br />\n";
In the above, I'm curious as to what the "name" is. To me, it looks like an array, but don't all arrays require the money sign ($) to be placed in front of them?
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

Re: Question about form input...

Post by juma929 »

Hello,

That is a HTML form array so you can access all elements using arrays in PHP, for example:

Code: Select all

 
<input type="text" name="item[]" value="test"/>
<input type="text" name="item[]" value="test two"/>
 
On your PHP page that retrieves the values you could then access each of those fields using arrays:

Code: Select all

 
$textfields = $_POST['item'];
 
foreach($textfields as $key => $value)
{
    echo $value . '<br/>';
}
 
 
If you need anything else let me know :).

Thanks.
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

Re: Question about form input...

Post by juma929 »

Hello,

Just to clarify, in HTML form arrays you dont need the dollar sign ($) :).

Thanks.
Wolf_22
Forum Contributor
Posts: 159
Joined: Fri Dec 26, 2008 9:43 pm

Re: Question about form input...

Post by Wolf_22 »

Thanks juma929. That cleared it up perfectly. :)
User avatar
juma929
Forum Commoner
Posts: 72
Joined: Wed Jun 17, 2009 9:41 am

Re: Question about form input...

Post by juma929 »

No problem, as I said if you ever need any more help at all just let me know and i'll do all I can :).

Thanks :D
Post Reply