PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Is there any INPUT type that is stored in an array on PHP?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Is there any INPUT type that is stored in an array on PHP?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/09/2007, 14h26   #1
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Is there any INPUT type that is stored in an array on PHP?

I want to show the user a list of emails and the user must have the
ability to select which ones he wants. Multiple selections must be
allowed. Any way I can do this? In PHP I want to do:

foreach ($_POST['contacts'] as $contact) {
// code...
}

But using Checkboxes doesn't work, I've tried putting them with the
same name but all that appears is a string of the LAST selected
checkbox :S. ?

  Réponse avec citation
Vieux 16/09/2007, 14h34   #2
Michael Fesser
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any INPUT type that is stored in an array on PHP?

..oO(RageARC)

>I want to show the user a list of emails and the user must have the
>ability to select which ones he wants. Multiple selections must be
>allowed. Any way I can do this? In PHP I want to do:
>
>foreach ($_POST['contacts'] as $contact) {
>// code...
>}
>
>But using Checkboxes doesn't work, I've tried putting them with the
>same name but all that appears is a string of the LAST selected
>checkbox :S. ?


Append [] to the names of the checkboxes, e.g.

<input type="checkbox" name="foo[]" value="42">

Then $_POST['foo'] will be an array.

Micha
  Réponse avec citation
Vieux 16/09/2007, 14h37   #3
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any INPUT type that is stored in an array on PHP?

Thanks Micha Didn't know that!

  Réponse avec citation
Vieux 16/09/2007, 14h43   #4
ptdorf@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any INPUT type that is stored in an array on PHP?

> But using Checkboxes doesn't work, I've tried putting them with the
> same name but all that appears is a string of the LAST selected
> checkbox :S. ?


I think you need check boxes here. html allow you to create many check
connected with the same name.

<input type="checkbox" name="options[1]" value="1" />Value 1
<input type="checkbox" name="options[2]" value="2" />Value 2
<input type="checkbox" name="options[4]" value="4" />Value 4


the submitted ones should appear as an $_POST array:
[options] => Array
(
[1] => 1
[4] => 4
)

  Réponse avec citation
Vieux 16/09/2007, 14h47   #5
RageARC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any INPUT type that is stored in an array on PHP?

Thanks guys, it really worked .

  Réponse avec citation
Vieux 16/09/2007, 18h43   #6
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is there any INPUT type that is stored in an array on PHP?

RageARC wrote:
> I want to show the user a list of emails and the user must have the
> ability to select which ones he wants. Multiple selections must be
> allowed. Any way I can do this? In PHP I want to do:
>
> foreach ($_POST['contacts'] as $contact) {
> // code...
> }
>
> But using Checkboxes doesn't work, I've tried putting them with the
> same name but all that appears is a string of the LAST selected
> checkbox :S. ?
>


Just remember - don't put the email address itself in your form - use
id's, etc. instead. And validate your data.

Spammers just love when you put the email address in a form field. And
they'll love you, also, right up to the time your site gets shut down.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h00.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09500 seconds with 14 queries