0

I am yorking in a laravel application. I have a form where I want to display checkboxes with javascript. I am getting the values of the checkboxes from the database.

Here is my code:

$.ajax({
    url: '/home/show',
    type: 'GET',
    data: 'id=' + selection,
    success: function(data) {
        //Build the checkboxes and the label for the termids
        var items ='{{Form::label("Linkids","Linkids", array( "class" => " col-sm-2 control-label")) }}';
        items += '<table class="table table-borderless" style="margin-right:10%;margin-left:90%"><tr style="border: 0;text-align: center;">';
        /* The variable j plays an important role in displaying the termids in rows since a borderless table was created for them */
        var j = 1;
        $.each(data, function (i, terms) {
            if(j < 8){
                items +='<label><td style="border: 0; text-align: center;">'+
                    **'<input style = "margin-left: 26px; margin-right: 0px;" type="checkbox" name="termids[]" value="'+terms.NewTermID+'"><p style="text-align:right">'**+'<b>'+terms.NewTermID+'</p>'+
                '</td></label>';  
                j++; 
            }
            else{
                j = 1;
                items += '</tr><tr>' ;
            }                         
        });
        items += '</tr></table>';
        $('#rData').html(items);
        $('#rData').show();
    } 
});

I want after a submit of the form repopulate the checkboxes with the submitted data. In my controoler I am using a validator:

if ($validator->fails()) 
{
    return Redirect::back()->withInput()
                           ->withErrors($validator)
                          ->with('message', 'There were validation errors.');
} 

I tried to use Input::old(terms) but I just get all the checkboxes checked!! and not the submitted checkboxes.

Any help would be really appreciated.

Thanks in advance.

JoriO
  • 1,050
  • 6
  • 13
user3481058
  • 313
  • 2
  • 4
  • 18

1 Answers1

0

If I'm correct you are using a combination of Blade syntax and normal html for your form, which is fine, but i think the auto-complete/repopulate procedure of Laravel works on Blade syntax elements.

Have you tried Blade only syntax?

{{ Form::checkbox('name', 'value', true) }}

The third argument 'true' denotes if a checkbox will be checked or not

nteath
  • 250
  • 1
  • 13