You are here:  » Dropdown list for free text field


Dropdown list for free text field

Submitted by CashNexus on Sun, 2022-04-03 05:27 in

Hello David,
hope you're doing well with these strange times...
Let me ask the following issue :

I've added free text field in /admin/feeds_register_step2.php where I put datafeed language (English, German, Spanish etc)

$userLanguageDefault = (isset($_POST["user_dflang"]) ? widget_safe(widget_posted($_POST["user_dflang"])) : "");
$prefixHTML = "<input type='text' name='user_dflang' value='".$userLanguageDefault."' />&nbsp;or use field&nbsp;";
field("Datafeed Language","dflang",$prefixHTML);

Everything works fine - but it annoys a little to type language name every time plus sometimes the usual human typing errors happens (for example Engish instead of English).

Is it possible to make a drop-down list of predefined languages for such a field ?
Thank you in advance for a hint,
Best regards,
Serge

Submitted by support on Mon, 2022-04-04 07:32

Sure - the input can be made a select box at that point; have a go with

$userLanguageDefault = (isset($_POST["user_dflang"]) ? widget_safe(widget_posted($_POST["user_dflang"])) : "");
$userLanguages = array("English","French","Spanish");
$prefixHTML = "<select name='user_dflang'>";
$prefixHTML .= "<option value=''>Select...</option>";
foreach($userLanguages as $userLanguage)
{
  $prefixHTML .= "<option ".($userLanguage==$userLanguageDefault?"selected='selected'":"")." value='".$userLanguage."'>".$userLanguage."</option>";
}
$prefixHTML .= "</select>";
$prefixHTML .= "&nbsp;or use field&nbsp;";
field("Datafeed Language","dflang",$prefixHTML);

Cheers,
David.
--
PriceTapestry.com

Submitted by CashNexus on Mon, 2022-04-04 20:04

SOLVED, thanks a lot ! Now much more convenient to use !
Take care yourself !
Best regards,
Serge