user2714362
user2714362

Reputation: 41

php html form rendering

I have written this html form and a php script. I want the title and sub-titles be rendered in bold and in different color. Any suggestions.

      <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>

Here is the php script

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

I have added some new code for more clarification.

Upvotes: 1

Views: 130

Answers (1)

Nikhil Kudtarkar
Nikhil Kudtarkar

Reputation: 169

You can declare a hiddenfield in your html which will hold number of title/para you have..

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

And change names in follwing syntax i.e. 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>

//
//Your PHP Part will now be

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

Upvotes: 2

Related Questions