Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:00:57+00:00 2026-06-05T18:00:57+00:00

I have a form with two input text fields: <input id=ModelName_test_0 name=ModelName[test][0] type=text> <input

  • 0

I have a form with two input text fields:

<input id="ModelName_test_0" name="ModelName[test][0]" type="text">
<input id="ModelName_test_1" name="ModelName[test][1]" type="text">

These input fields get generated with the following commands:

<?php echo $form->textField($model,'test[0]'); ?>
<?php echo $form->textField($model,'test[1]'); ?>

Now, when I submit the form I see the values in the POST request. However, when the form submit fails then I can not get the values back into the input fields. Printing the model it shows that there are no values for $test; – is this because $test is an array in the form?

Even after the validation all values are still assigned to the variables:

if($model->validate()) {
   echo "<pre>";
   print_r($_POST);
   return;
}

This returns:

[ModelName] => Array  
        (
            [test] => Array  
                (
                    [0] => myFirstInputField  
                    [1] => mySecondInputField
                )
        )

So the values are in the POST but after the failed validation they are gone and I get empty variables:

[ModelName] => Array  
        (
            [test] => 
        )

The variable test is declared safe in the validation rules.

What I want to achieve is:
If the validation fails put the entered values back into the appropriate input text fields.

Any pointers in the right direction would be helpful 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:00:58+00:00Added an answer on June 5, 2026 at 6:00 pm

    I found this article on the yiiframework.com website which helped me solving this issue: http://www.yiiframework.com/doc/guide/1.1/en/form.table

    This is the sample code which you would put it your controller:

    public function actionBatchUpdate()
    {
        // retrieve items to be updated in a batch mode
        // assuming each item is of model class 'Item'
        $items=$this->getItemsToUpdate();
        if(isset($_POST['Item']))
        {
            $valid=true;
            foreach($items as $i=>$item)
            {
                if(isset($_POST['Item'][$i]))
                    $item->attributes=$_POST['Item'][$i];
                $valid=$item->validate() && $valid;
            }
            if($valid)  // all items are valid
                // ...do something here
        }
        // displays the view to collect tabular input
        $this->render('batchUpdate',array('items'=>$items));
    }
    

    And this is what the view would look like:

    <div class="form">
    <?php echo CHtml::beginForm(); ?>
    <table>
    <tr><th>Name</th><th>Price</th><th>Count</th><th>Description</th></tr>
    <?php foreach($items as $i=>$item): ?>
    <tr>
    <td><?php echo CHtml::activeTextField($item,"[$i]name"); ?></td>
    <td><?php echo CHtml::activeTextField($item,"[$i]price"); ?></td>
    <td><?php echo CHtml::activeTextField($item,"[$i]count"); ?></td>
    <td><?php echo CHtml::activeTextArea($item,"[$i]description"); ?></td>
    </tr>
    <?php endforeach; ?>
    </table>
    
    <?php echo CHtml::submitButton('Save'); ?>
    <?php echo CHtml::endForm(); ?>
    </div><!-- form -->
    

    Both code snippets are taken from yiiframework.com where you can find more details on how to use ‘Tabular Inputs’: http://www.yiiframework.com/doc/guide/1.1/en/form.table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two fields <form action=insert.php method=post> Firstname: <input type=text name=firstname /> Lastname: <input
I have a form with two text_fields: <input type=text id=post_name name=post[name] /> <input type=text
I got two simple input text fields in a HTML form: <input type=text name=data[User][name]
I have a simple form and inside there are two input fields text type.
I have two fields in a form <div class=form> <label class=title>{'webmasterSubmitWebsite_rss_feed_title'|lang}</label> <div class=infos><input type=text
I have a form with the following two HTML elements: <input type=text name=vrm id=vrm
I have two buttons on my MVC form: <input name=submit type=submit id=submit value=Save />
I have a form with two input fields and a display text div: <div
I have a form with two input fields, one text and one send button.
On the form, I have one select and two input fields. These elements are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.