使用 zend 装饰器以 zend 形式在文本框后设置图像

发布于 2024-11-01 17:32:44 字数 7141 浏览 0 评论 0原文

我正在使用 zend 表单和 zend 装饰器来创建表单。我想在文本框后面设置图像。像这样: 在此处输入图像描述

我正在使用 zend 装饰器,但它给我的是这样的:

在此处输入图像描述

我正在使用以下代码:

类 CountryController 扩展了 Zend_Controller_Action {

public $textimage = array(
    'ViewHelper',
     array('FormElements',array('tag'=>'img')),
    'FormElements',
    array(array('openerror' => 'HtmlTag'),array('tag' => 'td', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND,'width'=>'37%')),
    'Errors',
    array(array('closeerror' => 'HtmlTag'),array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),

    array(array('elementImg' => 'HtmlTag'), array('tag' => 'img','class'=>'imgpos')),

    array('HtmlTag', array('tag' => 'td','align'=>'left')),
    array('Label', array('tag' => 'td')),

    array(array('row' => 'HtmlTag'), array('tag' => 'tr','valign'=>'top','align'=>'right')),
    );

public $elementDecorators = array(
    'ViewHelper',
    'FormElements',
    array(array('openerror' => 'HtmlTag'),array('tag' => 'td', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),
    'Errors',
    array(array('closeerror' => 'HtmlTag'),array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),

    array('HtmlTag', array('tag' => 'td', 'class' => 'element','align'=>'left','colspan'=>'2')),
    array('Label', array('tag' => 'td')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr','valign'=>'top','align'=>'right')),
);

public $buttonDecorators = array(
    'ViewHelper',
    'Errors',
    'FormElements',
    array('HtmlTag', array('tag' => 'td','align'=>'left')),
    array(array('row' => 'HtmlTag'), array('tag' => 'div')),
);

public $addButton = array(
    'ViewHelper',
    'Errors',
    'FormElements',
    array('HtmlTag', array('tag' => 'td','align'=>'right')),
    array(array('row' => 'HtmlTag'), array('tag' => 'div')),
);

//======================添加国家/地区操作===================== =======

公共函数 addAction() {

    $request = $this->getRequest();

    $form = new Zend_Form;
    $form->setAction('add')
        ->setMethod('POST')
        ->setAttrib('Name','addfrm')
        ->setAttrib('Id','addfrm');


    $form->addElements(array( 
             new Zend_Form_Element_Text('cou_name',array(
                    'decorators' => $this->textimage,

                  'required'   => true,
                  'label'      => 'Country Name :',
                    'class'=>'textpos',
                    'validator'=>'Alpha',
              )),
              new Zend_Form_Element_Textarea('description',array(
                    'decorators' => $this->textimage,
                  'required'   => true,
                  'label'      => 'Country Description :',
                    'rows'=>10,
                    'cols'=>40,
                    'validator'=>'NotEmpty',
                    'class'=>'textpos',
              )),
            new Zend_Form_Element_Checkbox('block',array(
                'decorators' => $this->elementDecorators,
                'Label'=>'Block :',
                'Value'=>'1',

              )),
              new Zend_Form_Element_Radio('block_r',array(
                'decorators' => $this->elementDecorators,
                'Label'=>'Block :',
                'multiOptions'=>array(0=>'Yes',1=>'No'),
                'Separator'=>'',
              )),
              new Zend_Form_Element_Submit('add',array(
                'decorators' => $this->addButton,
                'Label'=>'Add',
              )),
              new Zend_Form_Element_Button('back',array(
                'decorators' => $this->buttonDecorators,
                'Label'=>'Back',
                'onclick'=>'window.location="list"',
              )),
              ));


$form->setDecorators(array(
    'FormElements',
    array('HtmlTag', array('tag' => 'table','align'=>'center','class'=>'tbcss','width'=>'84%')), 
    'Form',

));

    $this->view->assign('form',$form);

} 。

我正在使用 IE6

生成的代码是这样的:

<div class="container">
     <form enctype="application/x-www-form-urlencoded" action="add"
    method="post" Name="addfrm" Id="addfrm" name="">
      <table align="center" class="tbcss" width="84%">
    <tr valign="top" align="right">
        <td id="cou_name-label"><label for="cou_name" class="required">Country
        Name :</label></td>


>     <td align="left"><img class="imgpos"> <input type="text"
>                   name="cou_name" id="cou_name" value="" class="textpos"
>                   validator="Alpha" />
>               <td width="37%"></td>
>               </img></td>

    </tr>
    <tr valign="top" align="right">
        <td id="description-label"><label for="description"
            class="required">Country Description :</label></td>
        <td align="left"><img class="imgpos"> <textarea
            name="description" id="description" rows="10" cols="40"
            validator="NotEmpty" class="textpos"></textarea>
        <td width="37%"></td>
        </img></td>
    </tr>
    <tr valign="top" align="right">
        <td id="block-label"><label for="block" class="optional">Block
        :</label></td>
        <td class="element" align="left" colspan="2"><input type="hidden"
            name="block" value="0" /><input type="checkbox" name="block"
            id="block" value="1" checked="checked" />
        <td></td>
        </td>
    </tr>
    <tr valign="top" align="right">
        <td id="block_r-label"><label class="optional">Block :</label></td>
        <td class="element" align="left" colspan="2"><label
            for="block_r-0"><input type="radio" name="block_r"
            id="block_r-0" value="0" />Yes</label><label for="block_r-1"><input
            type="radio" name="block_r" id="block_r-1" value="1" />No</label>
        <td></td>
        </td>
    </tr>
    <div>
    <td align="right"><input type="submit" name="add" id="add"
        value="Add" /></td>
    </div>
    <div>
    <td align="left">
    <button name="back" id="back" type="button"
        onclick=
    window.location = "list";
Back</button>
    </td>
    </div>
</table>
</form>
</div>

任何人都可以帮助我吗?

I am using zend form and zend decorator to create a form. and I want to set a image after a text box. like this:
enter image description here

I am using zend decorator but it is giving me like this:

enter image description here

I am using this code:

Class CountryController extends Zend_Controller_Action
{

public $textimage = array(
    'ViewHelper',
     array('FormElements',array('tag'=>'img')),
    'FormElements',
    array(array('openerror' => 'HtmlTag'),array('tag' => 'td', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND,'width'=>'37%')),
    'Errors',
    array(array('closeerror' => 'HtmlTag'),array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),

    array(array('elementImg' => 'HtmlTag'), array('tag' => 'img','class'=>'imgpos')),

    array('HtmlTag', array('tag' => 'td','align'=>'left')),
    array('Label', array('tag' => 'td')),

    array(array('row' => 'HtmlTag'), array('tag' => 'tr','valign'=>'top','align'=>'right')),
    );

public $elementDecorators = array(
    'ViewHelper',
    'FormElements',
    array(array('openerror' => 'HtmlTag'),array('tag' => 'td', 'openOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),
    'Errors',
    array(array('closeerror' => 'HtmlTag'),array('tag' => 'td', 'closeOnly' => true, 'placement' => Zend_Form_Decorator_Abstract::APPEND)),

    array('HtmlTag', array('tag' => 'td', 'class' => 'element','align'=>'left','colspan'=>'2')),
    array('Label', array('tag' => 'td')),
    array(array('row' => 'HtmlTag'), array('tag' => 'tr','valign'=>'top','align'=>'right')),
);

public $buttonDecorators = array(
    'ViewHelper',
    'Errors',
    'FormElements',
    array('HtmlTag', array('tag' => 'td','align'=>'left')),
    array(array('row' => 'HtmlTag'), array('tag' => 'div')),
);

public $addButton = array(
    'ViewHelper',
    'Errors',
    'FormElements',
    array('HtmlTag', array('tag' => 'td','align'=>'right')),
    array(array('row' => 'HtmlTag'), array('tag' => 'div')),
);

//======================add action for country============================

public function addAction()
{

    $request = $this->getRequest();

    $form = new Zend_Form;
    $form->setAction('add')
        ->setMethod('POST')
        ->setAttrib('Name','addfrm')
        ->setAttrib('Id','addfrm');


    $form->addElements(array( 
             new Zend_Form_Element_Text('cou_name',array(
                    'decorators' => $this->textimage,

                  'required'   => true,
                  'label'      => 'Country Name :',
                    'class'=>'textpos',
                    'validator'=>'Alpha',
              )),
              new Zend_Form_Element_Textarea('description',array(
                    'decorators' => $this->textimage,
                  'required'   => true,
                  'label'      => 'Country Description :',
                    'rows'=>10,
                    'cols'=>40,
                    'validator'=>'NotEmpty',
                    'class'=>'textpos',
              )),
            new Zend_Form_Element_Checkbox('block',array(
                'decorators' => $this->elementDecorators,
                'Label'=>'Block :',
                'Value'=>'1',

              )),
              new Zend_Form_Element_Radio('block_r',array(
                'decorators' => $this->elementDecorators,
                'Label'=>'Block :',
                'multiOptions'=>array(0=>'Yes',1=>'No'),
                'Separator'=>'',
              )),
              new Zend_Form_Element_Submit('add',array(
                'decorators' => $this->addButton,
                'Label'=>'Add',
              )),
              new Zend_Form_Element_Button('back',array(
                'decorators' => $this->buttonDecorators,
                'Label'=>'Back',
                'onclick'=>'window.location="list"',
              )),
              ));


$form->setDecorators(array(
    'FormElements',
    array('HtmlTag', array('tag' => 'table','align'=>'center','class'=>'tbcss','width'=>'84%')), 
    'Form',

));

    $this->view->assign('form',$form);

}
}

I am using IE6.

the generated code is this:

<div class="container">
     <form enctype="application/x-www-form-urlencoded" action="add"
    method="post" Name="addfrm" Id="addfrm" name="">
      <table align="center" class="tbcss" width="84%">
    <tr valign="top" align="right">
        <td id="cou_name-label"><label for="cou_name" class="required">Country
        Name :</label></td>


>     <td align="left"><img class="imgpos"> <input type="text"
>                   name="cou_name" id="cou_name" value="" class="textpos"
>                   validator="Alpha" />
>               <td width="37%"></td>
>               </img></td>

    </tr>
    <tr valign="top" align="right">
        <td id="description-label"><label for="description"
            class="required">Country Description :</label></td>
        <td align="left"><img class="imgpos"> <textarea
            name="description" id="description" rows="10" cols="40"
            validator="NotEmpty" class="textpos"></textarea>
        <td width="37%"></td>
        </img></td>
    </tr>
    <tr valign="top" align="right">
        <td id="block-label"><label for="block" class="optional">Block
        :</label></td>
        <td class="element" align="left" colspan="2"><input type="hidden"
            name="block" value="0" /><input type="checkbox" name="block"
            id="block" value="1" checked="checked" />
        <td></td>
        </td>
    </tr>
    <tr valign="top" align="right">
        <td id="block_r-label"><label class="optional">Block :</label></td>
        <td class="element" align="left" colspan="2"><label
            for="block_r-0"><input type="radio" name="block_r"
            id="block_r-0" value="0" />Yes</label><label for="block_r-1"><input
            type="radio" name="block_r" id="block_r-1" value="1" />No</label>
        <td></td>
        </td>
    </tr>
    <div>
    <td align="right"><input type="submit" name="add" id="add"
        value="Add" /></td>
    </div>
    <div>
    <td align="left">
    <button name="back" id="back" type="button"
        onclick=
    window.location = "list";
Back</button>
    </td>
    </div>
</table>
</form>
</div>

Can anyone help me plz.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小姐丶请自重 2024-11-08 17:32:44

在你的CSS中只需添加

.imgpos {
    float: right;
}

你也可以尝试向左浮动.textpos

In your css just add

.imgpos {
    float: right;
}

Also you can try float .textpos to left

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文