The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Using a for loop with an array?
Hi,
I'm having problems validating radio options from a form, before entering into the database. Because the names of the radio options change depending on the row id. I put my validation into a for loop, but it didn't work - nothing was posted from the form. PHP Code:
gender_{vb:raw id} free_{vb:raw id} active_{vb:raw id} id changes for each row pulled from the database, so we'll have Code:
HEADER Row 1: gender_1 | free_1 | active_1 Row 2: gender_2 | free_2 | active_2 Row 10: gender_10 | free_10 | active_10 If I use PHP Code:
Thanks in advance for your help. Iain |
#2
|
|||
|
|||
<a href="http://th2.php.net/manual/en/control-structures.foreach.php" target="_blank">http://th2.php.net/manual/en/control...es.foreach.php</a>
And it would be a lot easier ifyou used arrays like: GPC['gender'][] or better: GPC[]['gender'] |
#3
|
||||
|
||||
Thanks Marco, could you give me an example?
So, I would name my fields gender[{vb:raw id}], free[{vb:raw id}], active[{vb:raw id}]? How would I use foreach to use vbulletin's input cleaner? |
#4
|
|||
|
|||
If i have time i will try to put up an example tomorrow. But if you would use the id as array index, then you would only put the array itself through the input cleaner (GPC['gender']) and then loop through the resulting arrays.
|
#5
|
||||
|
||||
That would be great thanks =] I'll try and figure it out tho.
--------------- Added [DATE]1313870349[/DATE] at [TIME]1313870349[/TIME] --------------- Ok.. got somewhere. I have my fields named as: gender[{vb:raw id}], free[{vb:raw id}], active[{vb:raw id}] and my inputs being validated: PHP Code:
PHP Code:
Code:
$vbulletin->GPC['gender'][1] => 3. $vbulletin->GPC['gender'][2] => 3. $vbulletin->GPC['gender'][3] => 3. --------------- Added [DATE]1313874927[/DATE] at [TIME]1313874927[/TIME] --------------- Got it working! Thanks for your help Marco. So, you don't need multiple foreach loops, you just put your array in the first one. Here's the full working code if anyone's interested: PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|