填写 joomla 的表单域
我有一个用 joomla 制作的简单表格.我有两个电子邮件字段:
i have a simple form made with joomla. I have two fields for email:
echo $this->form->getLabel('email1');
echo $this->form->getInput('email1');
echo $this->form->getLabel('email2');
echo $this->form->getInput('email2');
当用户已经登录时,我正在尝试填写这些字段,但我遇到了问题.这是代码:
i'm trying to fill those fields when the user is allready logged in, but i have a issue. here is the code:
$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/>';
在输出中,字段的类型更改为
In the output, the fields's type change to
<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="">
我只想禁用这些字段并隐藏第二个字段
I just want to disabled those fields and hide the second field
感谢您的帮助
推荐答案
我找到了答案,希望对某人有所帮助:
I found the answer, hope that will help someone:
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'));
相关文章