Solved

PHP and html

Posted on 2000-05-04
4
189 Views
Last Modified: 2006-11-17
I have one problem. I am having two pages. In first page if I leave some mantitoy fields empty and if I click submit. The same first page must be displayed with changing the color(to red) of the names of the manditory fields that are not filled but all other data in other fields must be there. I don't know how to do it. Since I am new to php and using PHP3. Please help me.
0
Comment
Question by:balasundaram
  • 2
4 Comments
 
LVL 8

Expert Comment

by:us111
ID: 2779841
Try the form.php3 file


<?
function TestField($f)
{
if ($f == "")
      print "<font color='#FF0000'>";
}

$field_list = array("Name", "Firstname");

if ($REQUEST_METHOD == "POST")
{ for($i=0; $i<count($field_list);$i++)
  {     if ($$field_list[$i] == "")
          $err=true;
  }
  if ($err<>true)
     header("Location: confirm.php3");
}
?>

<form action="form.php3" method="post">
<?TestField($Name)?>Name</font>
<input type="text" value="<?print $Name?>" name="Name"><br>
<?TestField($Firstname)?>Firstname</font>
<input type="text" value="<?print $Firstname?>" name="Firstname"><br>
<input type="submit" value="submit" name="submit">
</form>
0
 

Author Comment

by:balasundaram
ID: 2788131
hello sir,

  your code works perfectly. but if I refresh the previous values are maintained. How I can overcome this problem?
0
 
LVL 8

Expert Comment

by:us111
ID: 2788445
Sure, when you refresh, you post again your data.
What do you need to do ?
0
 

Accepted Solution

by:
lar_aas earned 100 total points
ID: 2821793
<?
if (!(isset($have_doen_something))
  $have_doen_something = "nope";


if ($have_doen_something == "nope") {

 ## Do all your stuff

}
?>
<input type='hidden' name='have_doen_something' value='yes'>

This will in some cases be a workaround, but not always
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now