php html 表单渲染

标签 php html css

我已经编写了这个 html 表单和一个 php 脚本。我希望标题和副标题以粗体和不同颜色呈现。有什么建议。

      <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>";
}
?>

我添加了一些新代码以进行更多说明。

最佳答案

您可以在您的 html 中声明一个隐藏字段,它将包含您拥有的标题/段落的数量..

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

并更改以下语法中的名称,即 title1 from 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>

//
//您的 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>";
}
?>

关于php html 表单渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20658211/

相关文章:

PHP:数组中出现频率最高的值

javascript - 如何通过悬停来删除类(class)

php - 什么等同于 php 中 ruby​​ 的 =~?

php - 在移动设备中查看桌面站点(使用较少的框架)

PHP PDO 停止工作

html - CSS 将图像更改为将鼠标悬停在带有链接的图像上

html - 并排放置 2 个 div/Internet Explorer 6/7 float 和填充(?)错误修复

javascript - 下拉菜单需要起点

html - 如何在没有设置宽度的情况下居中对齐div

javascript - FFMPEG,使用图像选择区域插件模糊视频区域