How to create array of all the language in drupal form dropdown list(如何在drupal表单下拉列表中创建所有语言的数组)
问题描述
I need to create dropdown list for all languages in my Drupal form, Is there any function in PHP to achieve this. I want to create an array of all languages and pass it to drupal form.
function video_upload_subtitles_form($form, &$form_state) {
$form = array('#attributes' => array('enctype' => 'multipart/form-data'));
$lang_list = array();//**how to create this array**
$form['video_name'] = array(
'#title' => t('Name Of the video'),
'#type' => 'textfield',
);
$form['sub_file'] = array(
'#type' => 'file',
'#title' => t('Upload video'),
'#description' => t('Pick a video file to upload.'),
);
$form['user_list']=array(
'#type'=>'select',
'#title' => t('Language'),
'#options' => $lang_list,//array of language
'#multiple' => false,
'#attributes'=>array('size'=>4),
'#weight'=>8,
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
I know listing of language can be done in php by listing and making a array manually but is it possible to do with any php function, just looking for some easy way to save time.
Got this cool website for Country List . Is there anything for the Language like this
Try this,
$select = db_select('Your table name', 's');
$select = $select->fields('s',array('languages_name','id'));
// 'languages_name' , 'id' this is a column
$queried_nodes = $select->execute()
->fetchAllAssoc('id');
$lang_list = array();
foreach ($queried_nodes as $result)
{
$lang_list[$result->languages_name] = t($result->languages_name);
}
after set a $lang_list variable
$form['user_list']=array(
'#type'=>'select',
'#title' => t('Language'),
'#options' => $lang_list,//array of language
'#multiple' => false,
'#attributes'=>array('size'=>4),
'#weight'=>8,
);
you are create a new Language table or content types and you use a drupal inbuilt language list so try this code.
include_once DRUPAL_ROOT . '/includes/iso.inc';
$lang = _locale_get_predefined_list();
$lang_list = array();
foreach ($lang as $key => $value)
{
$lang_list[$value[0]] = t($value[0]);
}
after use a $lang_list
varible in form api
这篇关于如何在drupal表单下拉列表中创建所有语言的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在drupal表单下拉列表中创建所有语言的数组


基础教程推荐
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01