Page 1 of 1
Script not recognising last variable
Posted: Wed Oct 21, 2009 3:39 pm
by Puffmac
Hello,
I've got a script which checks if any variables are unset in the URL:
Code: Select all
function ProcessForm()
{
$InputFields = array( # All of the inputs we need
'dep','arr','fltno','cruise','fuel','resfuel',
'total','left','right','center','deptime','route',
'remarks'
);
for($i = 0;$i < sizeof($InputFields);$i ++)
{
if(!isset($_REQUEST[$InputFields[$i]]))
{
return false; # If any of the inputs aren't set, return false. This in turn creates the form via the Init function
}
}
Output::BuildFile();
return true; # By default return true, this line will be reached if all input fields are filled in.
}
However, it doe not recognise when the last variable is unset, it seems to skip it. I tested this theory by adding an empty value after 'remarks' in the InputFields array. It then returned false when remarks was unset. It also returns false if you remove remarks from the URL.
Please Help,
Thanks,
Andrew
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:47 pm
by requinix
Puffmac wrote:It then returned false when remarks was unset. It also returns false if you remove remarks from the URL.
This confuses me. What's the difference between "unset" and "not in the URL"?
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:53 pm
by Puffmac
tasairis wrote:Puffmac wrote:It then returned false when remarks was unset. It also returns false if you remove remarks from the URL.
This confuses me. What's the difference between "unset" and "not in the URL"?
Hi,
When I remove '&remarks=' from the URL, it is working properly. So I think it's something to do with the last value in the array. To test this what I did was add an extra value to the array:
Code: Select all
$InputFields = array( # All of the inputs we need
'dep','arr','fltno','cruise','fuel','resfuel',
'total','left','right','center','deptime','route',
'remarks','' # <<< There
);
It then worked properly, but that can't be nescessary, IMO. It must be something in my code.
Cheers,
Andrew
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:54 pm
by markusn00b
Hi, Andrew.
It works fine for me. What is the URL that is causing the trouble?
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:56 pm
by Puffmac
markusn00b wrote:Hi, Andrew.
It works fine for me. What is the URL that is causing the trouble?
Do you want a link?
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:56 pm
by markusn00b
Do you mean when $_GET['remarks'] has no value? If &remarks is present in the URL, it is 'set', so to speak. If you want to check whether they have a value, compare them against an empty string:
Code: Select all
function ProcessForm()
{
$InputFields = array( # All of the inputs we need
'dep','arr','fltno','cruise','fuel','resfuel',
'total','left','right','center','deptime','route',
'remarks'
);
for($i = 0;$i < sizeof($InputFields);$i ++)
{
if(!isset($_REQUEST[$InputFields[$i]]) || $_REQUEST[$InputFields[$i] == '')
{
return false; # If any of the inputs aren't set, return false. This in turn creates the form via the Init function
}
}
return true; # By default return true, this line will be reached if all input fields are filled in.
}
Mark.
P.S. If you know you're using GET, don't waste time by using REQUEST.
Re: Script not recognising last variable
Posted: Wed Oct 21, 2009 3:59 pm
by Puffmac
Mark,
Thanks very much. It works now

.
Re: Script not recognising last variable
Posted: Thu Oct 22, 2009 6:48 am
by markusn00b
Puffmac wrote:Mark,
Thanks very much. It works now

.
Welcome.
See ya around,
Mark.