我有一个带有多个文本字段的自定义表单,输入,没有值,并且想要验证字段,当所有输入都有值被禁用或者一旦插入值就不允许修改信息,条件是当当时每个人都有自己的价值,而且不可能更多。这应该用这种形式用php完成。
我正在创建这样的字段:
$form['general'] = array(
'#type' => 'details',
'#open' => true,
'#title' => $this->t('Configuración General'),
);
$form['general']['app_name'] = array(
'#type' => 'textfield',
'#title' => $this->t('Nombre'),
'#description' => $this->t(self::NAME_DESCRIPTION),
'#default_value' => $config->get('app_name'),
);
$form['general']['app_icon'] = array(
'#type' => 'managed_file',
'#name' => 'app_icon',
'#title' => t('Icono'),
'#default_value' => $config->get('app_icon'),
'#description' => t("This is the App icon! must be 1024x1024"),
'#required' => true,
'#upload_location' => 'public://files/icons/',
'#attributes' => array('class' => array('icons')),
);
$form['general']['app_logo'] = array(
'#type' => 'managed_file',
'#name' => 'app_logo',
'#title' => t('Logotipo'),
'#default_value' => $config->get('_app_logo'),
'#description' => t("This is the app Logo Must be 730x300"),
'#required' => true,
'#upload_location' => 'public://app/logos/',
'#attributes' => array('class' => array('icons')),
);
$form['general']['app_theme'] = array(
'#type' => 'radios',
'#title' => $this->t('Apariencia'),
'#description' => $this->t(self::THEME_DESCRIPTION),
'#options' => array(
'trabajo'=>'Trabajo',
'naturaleza'=>'Naturaleza',
'viajes'=>'Viajes',
'oficina'=>'Oficina',
'plano'=>'Plano',
),
'#multiple' => false,
'#default_value' => $config->get('app_theme'),
);
感谢您的帮助
答案 0 :(得分:0)
它解决了,我做了:
if (!empty($config->get('app_name')) && !empty($config->get('app_logo')) && (!empty($config->get('app_theme')))) {
$desabilitar = true;
}else {
$desabilitar = false;
}
并以表格形式插入:'#disabled'=> $ desabilitar,
$form['general'] = array(
'#type' => 'details',
'#open' => true,
'#disabled' => $desabilitar,
'#title' => $this->t('Configuración General'),
);