dtyyrt4545 2016-11-04 16:13
浏览 71

如果在PHP中使用自定义表单中的值,如何禁用字段? Drupal 8

I have a custom form with several text fields, input, without values and want to validate the fields and when all the inputs have value are disabled or not allowed to modify the information once that values were inserted, the condition is that when everyone has a value at that time desabilitan and can not be mofificar more. This should do it in this form with php necessarily.

I am creating the fields like this:

  $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'),
  );

thanks for your help

  • 写回答

1条回答 默认 最新

  • donglu953744 2016-11-04 19:32
    关注

    it´s solved, i did:

    if (!empty($config->get('app_name')) && !empty($config->get('app_logo')) && (!empty($config->get('app_theme')))) {
          $desabilitar = true;
        }else {
          $desabilitar = false;
        }
    

    and in the form insert : '#disabled' => $desabilitar,

    $form['general'] = array(
          '#type' => 'details',
          '#open' => true,
          '#disabled' => $desabilitar,
          '#title' => $this->t('Configuración General'),
        );
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向