1

I have two added form. In the first, I choose one client and for him I add several domains names. Then, when I clik to next, I arrived on a second form in which there are the several domains names (I added before ) in each row with others fields for each one (registar, url and remark). It seems to like this :

toto.com | Directnic | www.toto.com | blablabla
toto.fr | Afnic | www.toto.fr | bla
toto.net | Gandi | www.toto.net | blabla

But when I want to recover this data into my action to add them into my database, I get only the last line. Why ?

My form :

<form action="<?php echo url_for('@add_domaines');?>" method="post">

    <?php echo $form->renderGlobalErrors() ?>

    <table class="form_add_domaines">
        <thead>
            <tr>
                <th><?php echo $form['nom_domaine']->renderLabel()?></th>
                <th><?php echo $form['compte_registar_id']->renderLabel() ?></th>
                <th><?php echo $form['url']->renderLabel() ?></th>
                <th><?php echo $form['remarque']->renderLabel() ?></th>
            </tr>   
        </thead>

        <tbody>
            <?php 
            $domaines = explode("\n",$add_domaines);
            for($i=0; $i<count($domaines); $i++)
            {?> 
                <tr>
                    <td>
                        <?php 
                        if(1==strcmp(' ', $domaines[$i]))
                        {
                            echo "<span style='color:red;'>"."<b>Warning, missing domain name.</b>"."</span>";
                        }
                        else 
                        {
                            echo $domaines[$i];
                        }
                        ?>
                    </td>

                    <td>

                        <?php echo $form['compte_registar_id']->renderError() ?>

                        <?php echo $form['compte_registar_id'] ?>
                    </td>


                    <td>

                        <?php echo $form['url']->renderError() ?>

                        <?php echo $form['url'] ?>
                    </td>

                    <td>

                        <?php echo $form['remarque']->renderError() ?>

                        <?php echo $form['remarque'] ?>
                    </td>           
                </tr>
            <?php
            }
            ?>          
        </tbody>

        <tfoot>
            <tr>
                <td>
                    <?php echo link_to(__('Back', array(), 'sf_admin'), '@domaine_new') ?>
                </td>
                <td>

                    <?php echo $form->renderHiddenFields(false) ?>
                    <input type="submit" class="submit" value="Add" />
                </td>
            </tr>
        </tfoot>
    </table>
</form>

My action :

[...]    
$this->form = new AddDomainesForm();

$this->form->setDefault('client_id', $idClient);
$this->form->setDefault('nom_domaine', $noms_domaine);

if($request->isMethod('post'))
            {

                $name = $this->form->getName();

                $values = $request->getParameter($name);
                $files = $request->getFiles($name);

                $this->form->bind($values, $files);

                if($this->form->isValid())
                {
                    print_r($values);break;
                    //$this->form->save();

                    $this->getUser()->setFlash('notice', 'OK.');
                    $this->redirect('@domaine');
                }
            }

print_r($values) return only the last row of my form

Array ( [compte_registar_id] => 1 [url] => www.toto.net [remarque] => blabla [nom_domaine] => toto.com toto.fr toto.net [client_id] => 17 [_csrf_token] => ... )

Thank you !

4

1 回答 1

0

当多个表单元素具有相同名称时,只会取最后一个。

看到 cou 可以直接发送数组了吗?

<inut type="text" name="foobarlist[]">
<inut type="text" name="foobarlist[]">
<inut type="text" name="foobarlist[]">

$_GET['foobarlist'] 将返回一个包含 3 个元素的数组。

括号是关键。

于 2013-05-16T19:37:54.083 回答