dongtanxi5676756 2014-07-14 08:58
浏览 40
已采纳

生成表单 - 新的行和行动

I'm learning from Album tutorial for ZF 2.3.1.

In add.phtml I have the following code:

$form->setAttribute('action', $this->url('album', array('action' => 'add')));
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formHidden($form->get('id'));
echo $this->formRow($form->get('title'));
echo $this->formRow($form->get('artist'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();

The HTML output for this is:

<form action="&#x2F;album&#x2F;add" method="POST" name="album" id="album"><input type="hidden" name="id" value=""><label><span>Title</span><input type="text" name="title" value=""></label><label><span>Artist</span><input type="text" name="artist" value=""></label><input type="submit" name="submit" id="submitbutton" value="Add"></form>

However accoring to tutorial form should look like this: enter image description here

Questions:

  1. Why ZF2 doesn't generate any new lines tags as for example <p> or <div> between each line? In my browser all inputs are in the same line (maybe it's some styles issue not mentioned in tutorial) however I expected some extra tags will be generated

  2. Why in action /album/add is changed into &#x2F;album&#x2F;add - are there any security reasons for that? Action for form is set $form->setAttribute('action', $this->url('album', array('action' => 'add'))); but when I use the same method to generate link url <a href="<?php echo $this->url('album', array('action' => 'add')); ?>">test</a> it creates /album/add url as I expect

  • 写回答

1条回答 默认 最新

  • dssj88098 2014-07-14 09:43
    关注

    Why ZF2 doesn't generate any new lines tags as for example <p> or <div> between each line?

    One of the biggest criticisms of ZF1's forms system was that by programmatically generating form markup (using decorators) it made it difficult for users to customise the output. Consequently the helpers in ZF2 use minimal markup out of the box, allowing users to wrap the inputs with their own markup in views:

    <?=$this->form()->openTag($form)?>
    
    <?=$this->formHidden($form->get('id'))?>
    
    <div class="form-row">
        <?=$this->formRow($form->get('title'))?>
    </div>
    
    <div class="form-row">
        <?=$this->formRow($form->get('artist'))?>
    </div>
    
    [etc.]
    

    It is still possible to have this done automatically by extending the formRow helper.

    Why in action /album/add is changed into &#x2F;album&#x2F;add

    I'd never noticed this before. I'd guess the form class is set to automatically escape HTML attribute values (a good thing in general). It still seems to work just fine so I wouldn't worry about this too much. Perhaps open an issue for it on Github if you think the behaviour should be changed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化