填写joomla的表格字段

时间:2014-01-28 13:16:55

标签: php joomla

我有一个用joomla制作的简单表格。 我有两个电子邮件字段:

echo $this->form->getLabel('email1');
echo $this->form->getInput('email1');

echo $this->form->getLabel('email2');
echo $this->form->getInput('email2');

我正在尝试在用户已经登录时填写这些字段,但我有一个问题。 这是代码:

$user = JFactory::getUser();
$login = false;
if(!$user->get('guest')){
    $login = true;
    $email = $user->email;
}
...
echo '<input type="text" name="jform[email1]" class="validate-email required" id="jform_email1" value="'.$email.'" size="30" required="required" aria-required="true" disabled/><br>';
echo '<input type="hidden" name="jform[email2]" class="validate-email required" id="jform_email2" value="'.$email.'" size="30" required="required" aria-required="true" disabled/>';

在输出中,字段的类型更改为

<input type="email" name="jform[email1]" class="validate-email required" id="jform_email1" value="mail@mymail.com" size="30" required="required" aria-required="true" disabled="">
<input type="email" name="jform[email2]" class="validate-email required" id="jform_email2" value="mail@mymail.com" size="30" required="required" aria-required="true" disabled="">

我只想禁用这些字段并隐藏第二个字段

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

我找到了答案,希望能帮到某人:

echo $this->form->getLabel('email1');
$this->form->setValue('email1',null,$email);
$this->form->setFieldAttribute( 'email1', 'readonly', 'true' );
echo $this->form->getInput('email1');

echo $this->form->getLabel('email2', array('style' => 'display:none;'));
$this->form->setValue('email2',null,$email);
$this->form->setFieldAttribute( 'email2', 'readonly', 'true' );
echo $this->form->getInput('email2', array('type' => 'hidden'));