0

I am working on a lengthy form in laravel blade comprising of thousands of variables. I am using an array for name attribute in form. The form is submitting fine but sometimes I have an exception in my log that "php max variable limit of input variable exceeded" and some data gets missing on my records. Exceeding php max variable limit is not going to be working for me so I decided to serialize my form data into a single variable and pass it to laravel controller where I can un-serialize and use the data. But I am stuck at a point where my name attribute is an array. The thing I tried so far is :

my JS function

function submitForm() {
    var form_data = $("#edit-form").find(".check-enabled :input").serializeArray();
    var form_obj =  {'form_data' : form_data, "_token": $('#token').val()}

    if($(".submit-input-checks:checked").length==0)
    {
        swal("Please select atleast 1 Record");
        return false;
    }

    $.post("{{route('save_opps')}}", form_obj, function (data) {

    });

}

in my laravel controller, I am doing like

public function save(Request $request)
    {
        $data = $request->all();
        $data = unserialize($data['form_data']);
    }


but its not working like submitting form directly. The blade arrays are not converted to php array. How can I achieve this? or it there any better solution.

Edits request data dump

JAY PATEL
  • 559
  • 4
  • 17
Rehan Zia
  • 15
  • 6

1 Answers1

0
        $temp = explode('&',$request['form_data']);
        $data = [];
        foreach ($temp as $key => $value)
        {
            $pair =[];
            parse_str($value,$pair);
            foreach ($pair as $key  => $value1)
            {
                if(isset($data[$key]))
                {
                    array_push($data[$key], is_array($value1) ? $value1[0] : $value1);
                }else
                {
                    $data[$key] = [];
                    array_push($data[$key],is_array($value1) ? $value1[0] : $value1);
                }
            }

        }
     //use $data further

Arsii Rasheed
  • 324
  • 1
  • 5
  • 18