Page 1 of 3
Fixed(read the last post.you'll laugh, I know it:) )
Posted: Tue Sep 20, 2005 11:37 am
by Charles256
Code: Select all
foreach ($_POST as $key=>$value)
{
if ($key!='Register')
{
if ($value=='')
{
$varname="form_" .$key;
$$varname="<font color='RED'>Please enter something here.</font>";
$Error=1;
}
}
}
That's the loop... here's the form that's posted, or at least the part that should coincide with $key!='Register'
Code: Select all
<input type="submit" name="Register" value="Register">
and on the other page when it determines when to display the form looks like...
Code: Select all
if ($Error==1 || !(isset($Error)))
{
include('form.php');
}
Now obviously I submitted a blank form but the $Error=1 part didn't get executed because the form isn't displayed after it is submitted. any ideas?
Posted: Tue Sep 20, 2005 11:42 am
by Charles256
why? one of the keys passed from the form would be register wouldn't it?
<-- is appearantly confused..
Posted: Tue Sep 20, 2005 12:05 pm
by feyd
what was the field you left "blank" ?
Posted: Tue Sep 20, 2005 12:06 pm
by Charles256
I left every field blank. :-d Just submitted a blank form.
Posted: Tue Sep 20, 2005 12:21 pm
by feyd
are you sure they were in the $_POST array?
Re: function problems continued
Posted: Tue Sep 20, 2005 12:32 pm
by Buddha443556
Charles256 wrote:
Code: Select all
if ($Error==1 || !(isset($Error)))
{
include('form.php');
}
You should be getting a warning if $Error wasn't set. Got your error_reporting set to E_ALL?
Posted: Tue Sep 20, 2005 12:56 pm
by Charles256
Code: Select all
<form action="index.php?register=yes&process=yes" method="post">
that should put every field in the form in the post array,shouldn't it?
Posted: Tue Sep 20, 2005 1:20 pm
by John Cartwright
try adding this to your script
after the form has been submitted
Posted: Tue Sep 20, 2005 1:34 pm
by Charles256
Code: Select all
Array ( [Fname] =>
[Lname] =>
[Suffix] =>
[day] => 1 [month] => 1 [year] => 1900 [Email] =>
[Address] =>
[City] =>
[State] => Alabama [Zip] =>
[Register] => Register )
that's the output. to me it seems the values are blank...which means my if should be triggered,right?
[edit] rather most of them are blank:-D [/edit]
Posted: Tue Sep 20, 2005 1:38 pm
by ryanlwh
try if(!$value); They might be NULL, not blank.
Posted: Tue Sep 20, 2005 1:45 pm
by Charles256
it didn't work. I added
after the foreach loop and it echoed "0" so I'm sure that if isn't getting executed...
okay...this makes no sense.. I added the following code to my page..
in the foreach loop obviously and take a look at what it outputted...
Code: Select all
Fname ='
'Lname ='
'Suffix ='
'day ='1'month ='1'year ='1900'Email ='
'Address ='
'City ='
'State ='Alabama'Zip ='
'
which implies to me there is a break line in the form field but here is an example of how the form field looks
Code: Select all
<td><input type="text" name="Fname" value="<?php echo $Fname ?>" />
</td>
so why the devil is it picking up a break line?
Posted: Tue Sep 20, 2005 1:58 pm
by Charles256
oddly enough if i take out the PHP statement it takes out the break..but why would a php statement cause a break? I think my server hates me..

Posted: Tue Sep 20, 2005 2:01 pm
by ryanlwh
maybe $Fname in the form has a line-break already? Where did you get $Fname from?
Posted: Tue Sep 20, 2005 2:09 pm
by Charles256
i declared them above the foreach loop which is giving me a problem;-D
Code: Select all
$Fname=$_POST['Fname'];
$Lname=$_POST['Lname'];
$Suffix=$_POST['Suffix'];
$Day=$_POST['day'];
$Month=$_POST['month'];
$Year=$_POST['year'];
$Email=$_POST['Email'];
$Address=$_POST['Address'];
$City=$_POST['City'];
$State=$_POST['State'];
$Zip=$_POST['Zip'];
$Error=0;
I also declared error=0 because if later on none of the errors are triggered i need to know when to process the form, ya know?:-D as you can see $Fname is just what's posted in the form, so up until the form is submitted $Fname doesn't exist
Posted: Tue Sep 20, 2005 2:15 pm
by ryanlwh
what i meant is this
Code: Select all
<input type="text" name="Fname" value="<?php echo $Fname ?>" />
so this Fname is also initialized with the $_POST global array?