TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Counting for 1 ++ (http://www.talkphp.com/absolute-beginners/2415-counting-1-a.html)

paulOr 03-04-2008 01:07 PM

Counting for 1 ++
 
Iv got a really stupid problem, iv created a dynamic form, where the inputs can be added / removed by the user.
However i need to name each input uniquely, I.E textbox1, textbox2, textbox3 on and on...

The code i have for generating the textbox is this;

Code:

$form = new build_form;
        foreach($_SESSION['form'] as $element){
                if(strlen($element) > 0){
                        $form->$element('', 'name');
                }
        }

basicly its getting the elements and functions from my class, it works perfect, i just need a way to name with a number at the end, which will go up 1 for every input added.

How to do this? I managed to get it so it was putting in 2 textboxes ( when it should only be doing 1 ) and was naming them name1, name2 but then the next two that came in where also name1 and name2

Wildhoney 03-04-2008 02:39 PM

Can't you just give them a name of name1[] and name2[], then they'll simply get passed through as an array instead. Makes it much easier on both the Javascript and PHP side that way.

flyingbuddha 03-04-2008 03:56 PM

PHP Code:

foreach($_SESSION['form'] as $i=>$element){
    
$id 'name_'.$i;




All times are GMT. The time now is 07:11 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0