1

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.

2
  • 1
    Can you specify which elements are the title and subtitle? The labels or inputs? Which ones? Commented Dec 18, 2013 at 12:28
  • wrap them around span tags and then use normal classes or ids Commented Apr 11, 2016 at 17:58

1 Answer 1

2

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>";
}
?>
Sign up to request clarification or add additional context in comments.

2 Comments

It helped, but what if I need to include 'second_title' and 'second_para', and so on. Please.
# Nikhil much appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.