1

I have a Laravel form that looks like this...

 {!! Form::open(['action' => 'SitesController@store', 'method' => 'POST', 'id' => 'sites_create_form', 'enctype' => 'multipart/formdata']) !!}

 {{Form::label('s_name', 'Site Name')}}
                {{Form::text('s_name', '', ['class' => 'form-control', 'placeholder' => 'Site Name'])}}

 {!! Form::close() !!}

I also have a Javascript object containing an array of image ids, I would like to pass this to the controller so I can process the ids and add them to the resulting site.

I am thinking that the best option is to echo the array to a hidden form field and do it that way?

Is there a better way to do it, can I pass the javascript object directly to the controller?

1 Answer 1

1

If you are using Ajax requests, you could dynamically add the array of IDs to the form data before sending the request. I assume since you're using the form builder you aren't doing that.

Since you are most likely just sending the form "normally" then you answered your own question. Add a hidden field that includes the array as the value.

Make sure to sanitize input, just in case somebody changes the value of the field.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I thought that was the best use for my particular scenario but wanted some confimation. Thanks for the sanitize tip
@fightstarr20 if my answer solved your question (which it sounds like it did) please don't just up-vote it, accept the answer as well so other people see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.