Make sure the selects have a name="" attribute on them. Other than that, check the POST data in your browser to see what is sent (network tab in dev tools).
Input::all() on select options not quite working
I have a category page that has a couple of select menus to select a size and colour, but when selecting them it won't pass to a POST route it just shows as NULL why would this be, or is there a better way to do this? I also tried storing as a session but still to no avail.
Cheers.
Yes i have the name attribute on let me check Chrome dev tools
Nothing showing in the dev tools and a dd() shows
array (size=6)
'_token' => string '3GgtEIzsLSKNs11y3QrDquni1vCnlSKbjYS8VfE9' (length=40)
'colour' => null
'size' => null
'data' =>
So not sure @bashy
This is the HTML that outputs from my $vars
Colour: <select name="colour">
<option value="Blue">Blue</option>
<option value="Yellow">Yellow</option>
<option value="Green">Green</option>
<option value="Black">Black</option>
<option value="White">White</option>
</select>
Size: <select name="size">
<option value="14">14</option>
<option value="18">18</option>
<option value="22">22</option>
<option value="26">26</option>
</select>
When you want to test a POST open the network tab and reload the page, clear the list then proceed with the form submitting. After that you should see (at the top of the list) a route and a method of POST. If you click on that you can see the data sent via your browser.
Edit: the HTML looks fine.
That outputs:
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:284
Content-Type:application/x-www-form-urlencoded
Cookie:remember_82e5d2c56bdd0811318f0cf078b78bfc=eyJpdiI6InRJN0lCYkhnVGFjRHZGUExTd1NQTmc9PSIsInZhbHVlIjoiU3JEQWhwdkwwamRWbFNvNCtES3RhNGxaRENsSjk2T1ZidlFPWkdQOU5vaWJiVnNGdWx5NVV1ak5sampudjVYcHc4aTNWMk9DSE82Zjc3cW00d0ZnT2N5b29cLzN0YXdkRzFcLzZza0E2THVxWT0iLCJtYWMiOiJjYWQzOTUwOTg5OWRhODE3ODgxMjJjODNkZmIxYjlkNWVhZTk0ZGY4ZjFjNmYxOTFkNzcwY2VjYWY1MjIyZWI2In0%3D; cart_identifier=829c8c96b292121f8b203c00178ea5ba; laravel_session=eyJpdiI6IjA5eFZZMWU1UDFTdWNSK1R1YkZFdVE9PSIsInZhbHVlIjoiZGxmMjdkY1NcL1NkTll0eVIzdUVxZWJDZHlOOWNFdXF1TFR6OTdXRHJJaXljekExWXBZbnFZQ3VUNGo1SWtLU1JmcGNZYUtCTmxrd2d4U2JvWEg3Vm9BPT0iLCJtYWMiOiIwMmVkODI4NWRmMWJiNzc4N2JkODgxNjYzYTJhN2E5YjljN2JhN2JmZjZhZTkzM2UxMDJiNGY2YWZhYzk5NGQwIn0%3D
Host:clothing.app
Origin:http://clothing.app
Referer:http://clothing.app/category/new-in
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Form Dataview sourceview URL encoded
_token:3GgtEIzsLSKNs11y3QrDquni1vCnlSKbjYS8VfE9
pid:14
path:category/new-in
image:mXudQmkwoeBi.jpg
product_name:qwerty
delivery:3.99
stock:
size:
colour:
description:qwerty
qty:1
price:48.99
So size, colour still not getting passed the Input.
Can you show your blade file with the form?
@heliocorreia it's quite long so posted on pastebin - http://laravel.io/bin/Mk5Yb
Your Colour and Size inputs are outside of the form tags. Although you do have duplicates of both. A select and a hidden input.
Yes they are outside the form tags, as the user will select the options then the hiddent inputs should get these values of the selected option, or should I just move them inside the form tags @kreitje
Moving the form tag doesn't make any difference.
Looks like you have a second hidden colour select with a no value.
<input type="hidden" name="colour" value="">
If your browser isn't sending it, it's a HTML issue. Check the above
P.s remove your _token value in your reply. Don't want that displayed to others :P
_token value will change anyhow plus its local so no bother there.
as for the html im sure its fine and for the colour there is a bunch of isset's
like so:
@if (isset($item->colour))
<input type="hidden" name="colour" value="{{ Input::get('colour') }}">
@endif
@if (isset($item->colour_1))
<input type="hidden" name="colour" value="{{ Input::get('colour_1') }}">
@endif
@if (isset($item->colour_2))
<input type="hidden" name="colour" value="{{ Input::get('colour_2') }}">
@endif
@if (isset($item->colour_3))
<input type="hidden" name="colour" value="{{ Input::get('colour_3') }}">
@endif
@if (isset($item->colour_4))
<input type="hidden" name="colour" value="{{ Input::get('colour_4') }}">
@endif
@if (isset($item->colour_5))
<input type="hidden" name="colour" value="{{ Input::get('colour_5') }}">
@endif
@if (isset($item->colour_6))
<input type="hidden" name="colour" value="{{ Input::get('colour_6') }}">
@endif
Those isset-s have nothing to do with your dropdown. They are evaluated when the view is rendered, will not make anything when you change the dropdown value. That should be done by javascript. Why do you need the hidden fields anyway?
I don't know JavaScript enough to use it and I need hidden inputs to pass through to PayPal and stripe
Not sure what the {{ Input::get() }} is in each input? Do they have a value in when you view the source/inspect element?
Yes everything as a value on view source. I;m stumped.
The hidden inputs use the Input get method
Check over your source again, it's a problem in the HTML somewhere since the value isn't sending via your browser. Make sure there's no duplicates.
If the input has something in it, it should be sending it.
Yeah just checking now, bugging me off now
I can get it to work if it's pulling from the DB but I need to get the value of what the user will select from the two select menu's so looks like I need JS to do this, anyone know hoe based on what i've posted previously?? @bashy
Simply because I suck at JS
After googling i presume something like $( "#myselect" ).val(); would do the trick but then how would I assign that to the hidden inputs
So the values weren't set? :P
I normally use jQuery to change elements but that would get the val of the ID with myselect. Do you not want to do a onchange for the selects?
$('#selector').change(function() {
// something to change the value in input
});
@bashy the values are set but it's just not passing so i think the JS i posted above will work but then need to know how to pass that to PHP so i can use it.
Yeah I don't think it will update it with just that part of code. Just a question, why not just use the select boxes? Why the hidden field?
All i want it to do when i select a option from both menus it needs to get the value and then pass it to the payment page.
That make sense, still struggling with this.
Can't really work out what you have or what you want to do. I can think of two options but there's probably others
- Use an onchange="" to change the value of the hidden input when selecting from a select element.
- Use the select elements directly in the form so you can just straight away post the values to where ever.
Please or to participate in this conversation.