0

I am using Gravity Forms with WPML. I have some Dropdown and Checkboxes Fields. In English Dropdown and Checkboxes are in alphabetic order. All ok. But in my translation form, the system keeps the English order not the translation order. I would like to have a snippet that force Dropdown and Checkboxes fields to be in alphabetic order, no matter the language. I try to use the code below in my function.php without success. If someone could help it will make my day.

    add_filter("gform_pre_render_39", "sort_categories");
    function sort_categories($form){
    foreach($form["fields"] as &$field){
    if($field->id == 1)
        usort($field["choices"], "sort_numerically");
    }
    return $form;
    }
    function sort_numerically($a, $b){
    return floatval($a["text"]) > floatval($b["text"]);
    }

My ID form is 39 My ID Dropdown field is 1

Thank you for your help

Jean
  • 83
  • 3
  • 10
  • I wonder why your sorting function is trying to get the floatval of a string? are the choices a group of numbers? If you can export and attach the form here it will make things much easier to understand. – Sherif Aug 28 '20 at 10:09
  • Hi Sherif. Here is my code : Thank you for your time – Jean Aug 28 '20 at 23:06
  • Hi Jean, I meant the json export of the form, go to import/export and export the form then send the exported json. – Sherif Sep 08 '20 at 10:16

0 Answers0