0

I have form where I don't have submit button and actually the form didn't send post request, so my question how is possible to send request on image click?

@foreach($items as $item) <form class="form-horizontal" role="form" method="post" action="{{ route('index', $item->id) }}"> {{ csrf_field() }} <div class="col-md-3"> <div class="well"> <a><img class="img-responsive center-block" src="{{ $item->imagePath }}" alt=""></a> <h4 class="text-center">{{ $item->item_name }}</h4> </div> </div> </form> @endforeach 

Thank you

3 Answers 3

3

You can do it with jQuery. It's easy if you set id of the form:

$('form#form_id a').click(function(e){ $('form#form_id').submit(); e.preventDefault(); return false; }); 

But in your case you don't have any point in submitting post request, but anyway the above should work.

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

4 Comments

okey, not submitting, I want to send request, but this code doesn't work.
mean you want to go in controller method without submit? is this your question?
yes, i want to send the category id in the controller when i click on the image
You should include input fields with the values: <input name="category_id" value="{{ $item->id }}"> for example
0

Assuming that "Don't use a submit button" is not a hard requirement and you are just assuming that it is because you want to use an image:

Use a submit button instead of a link.

<button><img class="img-responsive center-block" src="{{ $item->imagePath }}" alt=""></button> 

You can style the default background and borders of the button away with CSS.

You really should have some content in the alt attribute. The image can't be a meaningless decorative image if it informs the user that clicking it will do something.

Comments

0

give id to your form in this way

<form action="" id="frm-id" method="post" class="form-horizontal "> 

next you js method will be as

$("#frm-id").submit(function(){ var form_data = $("#frm-id").serialize(); $.ajax({ url: '/index/'+id, type: "POST", }); }); 

At url above you need to your route to go in controller method as i wrote....

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.