Hello Guys, I have a form that i used array name.

ei. name[]

this is my code for input form

{{ Form::open(array('url' => 'create')) }}

            <TD><INPUT type="checkbox" name="chk[]"/></TD>

            <TD class="rating">
            {{ Form::text('core_values[]', Input::old('core_values[]'), array('placeholder' => 'Criteria Here')) }}</TD>
            {{ Form::textarea('behavioral[]', Input::old('behavioral[]'), array('placeholder' => 'Description Here', 'cols' => '75', 'rows' => '4')) }}
            <td class="rating">
            {{ Form::text('rating[]', Input::old('rating[]'), array('placeholder' => 'Percentage')) }}</td>

    {{ Form::submit('Submit!', array('class' => 'pull-right btn-warning')) }}
    {{ Form::close() }}

and this is my controler code

class SaveController extends BaseController {

    public function saveData()
            $input = Input::all();
            for ($idx = 0; $idx < count(Input::get('core_values')); $idx++)
                $values = new question;
                $values->core_values = $input['core_values'][$idx];
                $values->behavioral = $input['behavioral'][$idx];
                $values->rating = $input['rating'][$idx];
            // redirect
            Session::flash('message', 'Added!');
            return Redirect::to('evaluation');



my problem is, when i add 2 rows into database, only 1 rows added. whats wrong with my codes? iam not good in laravel. help me guys, thanks in advance. your help appreciated

Recommended Answers

All 2 Replies

I don't know laravel, but I think I would need to take a look at the method save() in the question class to see what it's doing with those values. Although, since you are in a loop, saving one item should lead to saving another. You might also want to var_dump($values); to see what you have in there.

I don't know if I'm even close to the answer, I don't know Laravel as I mentioned and I haven't even used a MVC framework before, so keep that in mind when reading my posts here.

I already uninstalled the laravel on my Development stack, because I am moving on to the Fuel PHP. However, I am worried about the for loop on your script. Will it be possible for you to use foreach loop which is more fitting to your situation? I do understand if you are coming from JAVA, C, and other languages.

In some cases, for loop will give you an error of ' undefined index ' on the last count position on the count function. To investigate it for yourself, please run this.. ( I don't have the chance to test it, but it should point out the points I am trying to convey).


    $array = array('a','b','c','d','e','f','g');
        for($y=0; $y <= count($array) ;$y++){
         echo $array[$y].'['.$y.']<br/>';

While this one is appropriate and more acceptable in PHP


   $array = array('a','b','c','d','e','f','g');
       $y = 0;
       foreach($array as $x){
         echo $x.'['.$y.'] <br/>';

To capture the array from the loop above, you will need to reassign the array something like this..

$thisArray[] = $x;
}//end of foreach loop

return $thisArray; // or do whatever you need to do with it.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.