Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
same name attribute value to several select controls
Old 04-05-2010, 10:30 AM same name attribute value to several select controls
Skilled Talker

Posts: 54
Trades: 0
is it possible to assign the name attribute of several select controls in a form the same name value and appending square brackets at end of the name value so that the various values selected in the several select controls will be available in an array when the form is submitted. this idea works with textboxes and checkboxes where if the textboxes are many they can be assigned the same name with square brackets at the end(eg name="txt[]") and the values of all of the textboxes will be available in an array when the form is submitted and each can be accessed by using any of of the php array fuctions (eg foreach($_POST['txt'] as $txt){........}).
eg
HTML Code:
<form action="submit.php" method="post">Text1<input type="text" name="txt[]" value=""/>Text2<input type="text" name="txt[]" value=""/>Text3<input type="text" name="txt[]" value=""/></form>
server side:
PHP Code:
foreach($_POST['txt'] as $txt){echo $txt
the above code will output each of the textbox values in turn.
kani alavi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-05-2010, 02:32 PM Re: same name attribute value to several select controls
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
The [] are actually invalid characters in element attributes and there is ABSOLUTELY no need to do ANYTHING to return form elements as an array.

Simply by using the same value in the name attribute (without the []) all the ACTIVE values will be returned as a comma separated string, and it doesn't take much imagination to turn that into an array!
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to same name attribute value to several select controls
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10528 seconds with 12 queries