Arend Posted January 6, 2022 Share Posted January 6, 2022 Struggling with a dropdown menu in a form. What I have is a plugin for Wordpress to make extra fields in an excisting form. The problem that the menu is not filling with values and what ever I do nothing good is happening. Could someone please help to get on the right track? Greetz Arend The code I am using; function gma_wpjmef_frontend_add_doelgroep_info_field( $fields ) { $fields['job']['job_doelgroep_info'] = array( 'label' => __( 'Select One ', 'extra-field' ), 'type' => 'select', 'required' => false, 'placeholder' => '', 'omschrijving' => '', 'priority' => '8', 'be' => 'Belgium', 'lu' => 'Luxembourgh', 'nl' => 'Netherlands' , ); foreach ($fields['job']['job_doelgroep_info'] as $key => $value) { echo ' <option value="<echo $value; >"<<echo $key;></option>'; }; return $fields; } Quote Link to comment https://forums.phpfreaks.com/topic/314394-dropdown-in-array-and-foreach/ Share on other sites More sharing options...
Barand Posted January 6, 2022 Share Posted January 6, 2022 Too many <..>s and echos. Try echo "<option value='$value'>$key</option>"; (Note use of outer double quotes) Please use the <> button when posting code Quote Link to comment https://forums.phpfreaks.com/topic/314394-dropdown-in-array-and-foreach/#findComment-1593216 Share on other sites More sharing options...
Arend Posted January 7, 2022 Author Share Posted January 7, 2022 Thank ypu for your input. I took a look in the templates of Wordpress and came up with a solution This code is working for me maby someone good use this also. ;=)) Greetz Arend < function gma_wpjmef_frontend_add_doelgroep_info_field( $fields ) { $fields['job']['job_doelgroep_info'] = array( 'label' => 'Select', 'type' => 'select', 'required' => false, 'placeholder' => '', 'omschrijving' => '', 'priority' => '8', 'options' => array( 'option1' => 'This is option 1', 'option2' => 'This is option 2' ) ); return $fields; } > Quote Link to comment https://forums.phpfreaks.com/topic/314394-dropdown-in-array-and-foreach/#findComment-1593229 Share on other sites More sharing options...
ginerjm Posted January 7, 2022 Share Posted January 7, 2022 Can I ask - why do you need this function? All it does is create a single entry in an array and never anything else. What's the point? You could simply place this code in your mainline code and not have to create a function. Quote Link to comment https://forums.phpfreaks.com/topic/314394-dropdown-in-array-and-foreach/#findComment-1593231 Share on other sites More sharing options...
ginerjm Posted January 7, 2022 Share Posted January 7, 2022 Actually I should have said - "create the SAME single entry in an array". Which kind of makes it a needless function. Quote Link to comment https://forums.phpfreaks.com/topic/314394-dropdown-in-array-and-foreach/#findComment-1593233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.