Search for Resources and Solutions

set_plans_options - add dropdown in the plans

From the Midrub version 0.0.8.2 you can add dropdowns with the function set_plans_options. This is a little hard but works very well if you're following the instructions below.

By default i'm using the dropdown in the plans for the plans groups and redirect for plan after login.

The select_dropdown will add a dropdown with search support. It's structure is:

array (

    'type' => 'select_dropdown',

    'slug' => 'slug which should be unique',

    'url' => 'url for ajax's requests',

    'label' => 'oprion's label',

    'label_description' => 'label's description',

    'placeholder' => 'text displayed in the search input'

The url is very important. Ensure it is correct. 

The url will receive these POST's parameters:

  • plan_id - current plan's ID.
  • option - the slug's value which you're seeing above, will be sent.
  • key - search key when the administrator searches for option.

Should return maximum 10 results.

The function which will receive the ajax requests at your url is reload_plan_dropdown. 

The function reload_plan_dropdown should display in a json these keys:

// Prepare the success message

$data = array(

    'success' => TRUE,

    'response' => $response,

    'option' => $option

);

// Display the success message

echo json_encode($data);

Option should be the received option.

Response(key) should have as value:

  • default - what will be displayed in the dropdown's button.
  • selected -> array('id' => 'selected id', 'name' => 'item's name'); This will be if the administrator has selected an item.
  • items -> array(array('id' => 'item's id', 'name' => 'item's name'), array('id' => 'item's id', 'name' => 'item's name')). If items exists.
  • no_items_message - text message if no items.

You don't need to take care about other things.



Was this article helpful?