[SOLVED]error message placing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

[SOLVED]error message placing

Post by pleigh »

if i do this technique

Code: Select all

if (isset($_POST['submit']))
{
	$message = NULL;
	
	//check for project title
	if (empty($_POST['projecttitle']))
	{
		$pt = false;
		$message .= 'You forgot to enter the project title<br>';
	}
	else
	{
		$pt = $_POST['projecttitle'];
	}

        if ($pt)
       {
              //sql code goes here
       }
}

if (isset($message))
{
	echo '<font color=red>'.$message.'</font>';
}
then my form will be

Code: Select all

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input name="projecttitle" type="text" size="31" value="<? if (isset($_POST['projecttitle'])) echo $_POST['projecttitle']; ?>">
<input type="submit" name="submit" value="submit" class="buttonformat" />
the result of this is when the user supplied a blank character in the textbox, the error message will appear above the form, right?now, the deal is that, i want the error message to appear right after the textbox...can u guys help me modify the above code so i can attain this idea?thanks in advance.. :)
Last edited by pleigh on Mon Aug 29, 2005 5:32 am, edited 1 time in total.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: error message placing

Post by s.dot »

pleigh wrote:if i do this technique

Code: Select all

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input name="projecttitle" type="text" size="31" value="<? if (isset($_POST['projecttitle'])) echo $_POST['projecttitle']; ?>">
<input type="submit" name="submit" value="submit" class="buttonformat" />
Perhaps it should be:

Code: Select all

<input name="projecttitle" type="text" size="31" value="<? if (isset($_POST['projecttitle'])) echo $_POST['projecttitle']; ?>"> <? if($pt = "false"){ echo $errormessage; } ?>
Or perhaps I'm not grasping your question right :P
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I suggest you use associative arrays for this. for eg.

Code: Select all

if (isset($_POST['submit'])) 
{ 
    $error = array(); 
     
    //check for project title 
    if (empty($_POST['projecttitle'])) 
    { 
        $pt = false; 
        $error['projecttitle'] = 'You forgot to enter the project title<br>'; //set the projecttitle error...
    } 
    else 
    { 
        $pt = $_POST['projecttitle']; 
    } 

        if ($pt) 
       { 
              //sql code goes here 
       } 
}
and in the form you output the err like this

Code: Select all

<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" > 
<input name="projecttitle" type="text" size="31" value="<? if (isset($_POST['projecttitle'])) echo $_POST['projecttitle']; ?>">
<? if (isset($error['projecttitle'])) echo $error['projecttitle']; ?>
<input type="submit" name="submit" value="submit" class="buttonformat" />
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

Post by pleigh »

thanks noob saibot it perfectly works... :D
Post Reply