Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to retrieve data from multiple select box in Slim framework

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 935
    Comment on it

    Retrieve data from multiple select box in Slim framework

    Hello friends, welcome to findnerd. Today I am going to tell you how to fetch data in array from multiple select box in Slim framework. Follow the steps below:

     

    Step 1: Lets begin by marking your select box field as follows:

     

    <form action="/admin/fetchdata">
    <select name="city[]" class="form-control" id="city" multiple="multiple">
      <option value="">Select City</option>
       {% for value in cities %}
       {% if value.city_name !='' %} 
       <option value="{{ value.city_name }}">{{ value.city_name }}</option>
       {% endif %} 
       {% endfor %}
      </select>
    </form>

     

    Adding the attribute 'multiple' to the select box, it will allow the user to select more than 1 options. User will need to hold ctrl or shift command in order to select multiple options. You can set the 'size' attribute of the select box to show larger size , so that more options are visible to the user. So after adding the above html code, following html page will be displayed as shown:

     

     

     

    ***Note: For selecting multiple options at a time from select box, you need to add square brackets after the name.

     

    Step 2: Now you can add the following code to the controller in order to fetch the data:

     

    $app->post('/admin/fetchdata', function () use ($app) {
        echo "<pre>";
        print_r($app->request->params('city'));
        echo "</pre>";
    }

     

     

    Select the following options as shown below:

     

     

     

    print_r($app->request->params('city')): This will show you the following output:

     

    Array
    (
        [0] => Bangalore
        [1] => Dehradun
        [2] => Delhi
    )

     

     

    All done!

     

    Thanks for reading the blog.

    How to retrieve data from multiple select box in Slim framework

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: