2013-12-18 27 views
1

我写过这个html表单和一个php脚本。我希望标题和子标题以粗体和不同颜色呈现。有什么建议么。php html form rendering

 <form action="myscript.php" method="POST"> 
     <fieldset> 

      #title# 

      <p><label for="title"></label> 
      <input type="text" name="title" size="60" /></p> 


      <p><label for="Introduction"></label> 
      <textarea cols="width" rows="height" name="introduction">Introduction...</textarea></p>    

      #first_title or subtitle# 

      <p><label for="first_title"></label> 
      <input type="text" name="first_title" size="60" value="first para title..."></p> 


      <p><label for="first_para"></label> 
      <textarea cols="width" rows="height" name="first_para">first paragraph...</textarea></p> 

    #second_title or subtitle# 

    <p><label for="second_title"></label> 
    <input type="text" name="second_title" size="60" value="second para title..."></p> 


    <p><label for="second_para"></label> 
    <textarea cols="width" rows="height" name="second_para">second paragraph...</textarea></p> 



     <br /> 

      <fieldset class="center"> 
      <input type="submit" value="" /> 
      <input type="reset" value="Clear and Restart" /> 
     </fieldset> 
    </form> 

这里是PHP脚本

<?php 
foreach($_REQUEST as $value) { 
echo "<p>" . $value . "</p>"; 
} 
?> 

我增加了一些新的代码,更多的澄清。

+1

你能指定哪些元素是标题和副标题吗?标签或输入?哪个? – SW4

+0

将它们包裹在span标签上,然后使用正常的类或ID –

回答

2

可以声明在HTML一个hiddenfield将举行您有标题/对数..

<input type="hidden" name='counter' value='2'/> 

而且从first_title

<p><label for="first_title"></label> 
     <input type="text" name="title1" size="60" value="first para title..."> 
</p> 
<p><label for="first_para"></label> 
     <textarea cols="width" rows="height" name="para1">first paragraph...</textarea> 
</p> 

<p><label for="first_title"></label> 
     <input type="text" name="title2" size="60" value="second para title..."> 
</p> 
<p><label for="first_para"></label> 
     <textarea cols="width" rows="height" name="para2">second paragraph...</textarea> 
</p> 

follwing语法即title1更改名称//
//你的PHP部分现在将是

<?php 

$count=$_REQUEST['counter']; 

for($i=1;$i<=$count;$i++) 
{ 
echo "<p style='font-weight:bold;'>" . $_REQUEST['title'.$i] . "</p>"; 
echo "<p>" . $_REQUEST['para'.$i]. "</p>"; 
} 
?> 
+0

它有帮助,但是如果我需要包含'second_title'和'second_para',等等。请。 – user2714362

+0

你是如何产生更多的旁边,我可以看到代码? –

+0

#Nikhil,我已经为你编辑了这篇文章。 – user2714362