2010-12-11 41 views
0

有没有更好的方式来处理PHP中的表单标签顺序而不是这个?是否有更好的方式来处理PHP中的表单标签顺序而不是这个?

我有多个重复的表单的页面。由于布局我希望tab顺序是非顺序的,所以我必须在html中指定它(以便我可以不按顺序指定它)。我的形式使用PHP的块引用机制,据我可以做出来不允许块

我实现了这里面的PHP变量算术,但我的实现看起来别扭构建。我不禁想到有一个更优雅的方式来做到这一点。

首先我在页面顶部初始化一些PHP变量。

$tab1=1; 
$tab2=2; 
$tab3=3; 
$tab4=5; 
$tab5=4; 

然后后来,一个PHP循环我做这里面......

$tab1+=5; 
$tab2+=5; 
$tab3+=5; 
$tab4+=5; 
$tab5+=5; 

然后将变量添加到块引用...

$picshtml .= <<<BLOCK 
<div class="addcomment"> 
    <a href="">Add Comment</a><br /><br /> 

    <div id="commentform$row[photoid]" class="commentform"> 
     <div id="submitanim$row[photoid]" style="display:none"> 
      <img src="loadingAnimation.gif" alt="Processing..." /> 
     </div>  
     <form action=""> 
      <div style="float:left;clear:left;text-align:right"> 
       Comment<br />Name <input type="text" id="name$row[photoid]" tabindex="$tab1" /> <br /> 
       Email <input type="text" id="email$row[photoid]" tabindex="$tab2" /><br /> 
       Website <input type="text" id="website$row[photoid]" tabindex="$tab3" /><br /> 
       <input type="button" value="Submit Comment" id="submit$row[photoid]" onclick="javascript:ajax($row[photoid])" tabindex="$tab4" /> 
      </div> 
      <textarea rows="5" cols="50" id="comment$row[photoid]" tabindex="$tab5" ></textarea> 
     </form> 
    </div> 
</div> 

BLOCK; 
+0

如果我有因缘编辑这个,我会帮助你的。代替对代码使用反引号标记,请尝试使用4个空格缩进代码行。 – scoates 2010-12-11 21:49:09

+0

最终得到了它的hang ... ......反面的事情让它变得无法正确。相反,我只是使用按钮来添加4个空格。 – MrVimes 2010-12-11 21:52:06

回答

1

如何sprintf

$html = <<<BLOCK 
... 
<input type="text" tabindex="%d" /> 
... 
BLOCK; 

$order = 0; 

$html = sprintf($html, $order, $order + 1, $order + 2, $order + 3, $order + 4, $order + 5, ...); 

$order += 6; 

// ... 

语法参考这里:

http://php.net/sprintf

+0

完美!诀窍了。谢谢 :) – MrVimes 2010-12-11 22:01:40

相关问题