2013-12-18 104 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