0

I have created a very simple form in laravel..

<?php
 echo Form::selectRange('number', 2, 12);
 echo Form::submit('Click Me!');
?>

However, at this time I am unclear of how to send the selected value of the DDL to the server to perform a task depending on which value is selected. For example, if 3 is selected it would send you to a specific view that would be different than if 4, 5, or 6 was selected. I checked out the documentation and couldn't find the direction I should go.

asked Dec 14, 2013 at 21:26

1 Answer 1

1

I believe that if you see the posted data, you'll see a field number with the value selected in the input. In laravel you access to such variables as

$number = Input::get('number');
...

Hope it helps!

EDIT You also need to open and close the form:

{{ Form::open(array('url' => 'foo/bar')) }}
 {{ Form::selectRange('number', 2, 12) }}
 {{ Form::submit('Click Me!') }}
{{ Form::close() }}

EDIT2 Your routes.php should have something like this:

Route::post('foo/bar', function()
{
 $number = Input::get('number');
 .....
});
answered Dec 14, 2013 at 21:31
Sign up to request clarification or add additional context in comments.

3 Comments

I tried adding: $number = Input::get('number'); then echo $number; There is no output in my HTML. From everything I am looking at, maybe I need to create a controller to handle the logic?
So, with the code <?php Form::open(array('url' => 'foo/bar')); Form::selectRange('number', 2, 12); Form::submit('Click Me!'); Form::close(); $number = Input::get('number'); echo $number; ?> The form no longer shows on the page, any idea why?
I think I understand you now... First: You have to either echo every call to Form or use blade syntax. Second: the $number = Input::get('number'); code must be inside a function handling the POST request (when you submit the form). Look at my second edit

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.