Validate variables w/out empty

This is a discussion on Validate variables w/out empty within the PHP Language forums, part of the PHP Programming Forums category; I have a working couple of pages (form submits 2 variables to the second page using GET). page1 has two ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-01-2007
pgt
 
Posts: n/a
Default Validate variables w/out empty

I have a working couple of pages (form submits 2 variables to the second
page using GET).

page1 has two dropdowns (generated from MySQL db).

page2 retrieves info from the database accordingly, depending on the passed
variables. Works fine.


I need to ensure that the user has actually selected both variables on page1
from each of the drop down options on page1.

empty() seems unable to do this because the default drop down options are
"Select one", "Select the other".

so on page2, if the user has NOT made any choices:

echo "Values passed to GET method:<br />\n";
reset ($_GET);
while (list ($key, $val) = each ($_GET)) {
echo "$key => $val<br />\n";
}

gives me:
Select one
Select the other


I can not see how to use empty() or isset() to resolve this, so...

Any ideas how to ensure the user has selected something from both options
(without javascript)?

I couldn't find anything in the manual but assume I'm looking in all the
wrong places for this.

Thank you.





Reply With Quote
  #2 (permalink)  
Old 11-01-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Validate variables w/out empty

pgt wrote:
> I have a working couple of pages (form submits 2 variables to the second
> page using GET).
>
> page1 has two dropdowns (generated from MySQL db).
>
> page2 retrieves info from the database accordingly, depending on the passed
> variables. Works fine.
>
>
> I need to ensure that the user has actually selected both variables on page1
> from each of the drop down options on page1.
>
> empty() seems unable to do this because the default drop down options are
> "Select one", "Select the other".
>
> so on page2, if the user has NOT made any choices:
>
> echo "Values passed to GET method:<br />\n";
> reset ($_GET);
> while (list ($key, $val) = each ($_GET)) {
> echo "$key => $val<br />\n";
> }
>
> gives me:
> Select one
> Select the other
>
>
> I can not see how to use empty() or isset() to resolve this, so...
>
> Any ideas how to ensure the user has selected something from both options
> (without javascript)?
>
> I couldn't find anything in the manual but assume I'm looking in all the
> wrong places for this.
>
> Thank you.
>
>
>
>
>
>


Some code would help...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #3 (permalink)  
Old 11-01-2007
Rik Wasmus
 
Posts: n/a
Default Re: Validate variables w/out empty

On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:

> I have a working couple of pages (form submits 2 variables to the second
> page using GET).
>
> page1 has two dropdowns (generated from MySQL db).
>
> page2 retrieves info from the database accordingly, depending on the
> passed
> variables. Works fine.
>
>
> I need to ensure that the user has actually selected both variables on
> page1
> from each of the drop down options on page1.
>
> empty() seems unable to do this because the default drop down options are
> "Select one", "Select the other".
>
> so on page2, if the user has NOT made any choices:
>
> echo "Values passed to GET method:<br />\n";
> reset ($_GET);
> while (list ($key, $val) = each ($_GET)) {
> echo "$key => $val<br />\n";
> }
>
> gives me:
> Select one
> Select the other
>
>
> I can not see how to use empty() or isset() to resolve this, so...
>
> Any ideas how to ensure the user has selected something from both options
> (without javascript)?
>
> I couldn't find anything in the manual but assume I'm looking in all the
> wrong places for this.


Give the option a value 0 (well, it's more transparant/reliably checked
then for the string 'Select one', and check if(!isset($_GET['option1']) ||
$_GET['option1'] = 0) echo 'Please select an option.';

Or you could 'whitelist' options. So you have an array of possible
options, and check:
$array = array(...);
if(!isset($_GET['option1']) || !in_array($_GET['option1'],$array)) echo
'Please select.';
--
Rik Wasmus
Reply With Quote
  #4 (permalink)  
Old 11-01-2007
pgt
 
Posts: n/a
Default Re: Validate variables w/out empty


"Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.t0203pi85bnjuv@metallium.lan...
On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:

> I have a working couple of pages (form submits 2 variables to the second
> page using GET).
>
> page1 has two dropdowns (generated from MySQL db).
>
> page2 retrieves info from the database accordingly, depending on the
> passed
> variables. Works fine.
>
>
> I need to ensure that the user has actually selected both variables on
> page1
> from each of the drop down options on page1.
>
> empty() seems unable to do this because the default drop down options are
> "Select one", "Select the other".
>
> so on page2, if the user has NOT made any choices:
>
> echo "Values passed to GET method:<br />\n";
> reset ($_GET);
> while (list ($key, $val) = each ($_GET)) {
> echo "$key => $val<br />\n";
> }
>
> gives me:
> Select one
> Select the other
>
>
> I can not see how to use empty() or isset() to resolve this, so...
>
> Any ideas how to ensure the user has selected something from both options
> (without javascript)?
>
> I couldn't find anything in the manual but assume I'm looking in all the
> wrong places for this.



Give the option a value 0 (well, it's more transparant/reliably checked
then for the string 'Select one', and check if(!isset($_GET['option1']) ||
$_GET['option1'] = 0) echo 'Please select an option.';




Still missing something here then:

page1
<select name="this">
<option value="0">Select one</option>
</select>
<select name="that">
<option value="0">Select the other</option>
</select>


page2
if (!isset($_GET['var1']) || $_GET['var1'] = "0")
{ echo 'Go back and select the first choice.'; }

if (!isset($_GET['var2']) || $_GET['var2'] = "0")
{ echo 'Go back and select your second choice.'; }


What am I missing with this please?

Thanks for any help.








Reply With Quote
  #5 (permalink)  
Old 11-01-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Validate variables w/out empty

pgt wrote:
> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
> news:op.t0203pi85bnjuv@metallium.lan...
> On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
>
>> I have a working couple of pages (form submits 2 variables to the second
>> page using GET).
>>
>> page1 has two dropdowns (generated from MySQL db).
>>
>> page2 retrieves info from the database accordingly, depending on the
>> passed
>> variables. Works fine.
>>
>>
>> I need to ensure that the user has actually selected both variables on
>> page1
>> from each of the drop down options on page1.
>>
>> empty() seems unable to do this because the default drop down options are
>> "Select one", "Select the other".
>>
>> so on page2, if the user has NOT made any choices:
>>
>> echo "Values passed to GET method:<br />\n";
>> reset ($_GET);
>> while (list ($key, $val) = each ($_GET)) {
>> echo "$key => $val<br />\n";
>> }
>>
>> gives me:
>> Select one
>> Select the other
>>
>>
>> I can not see how to use empty() or isset() to resolve this, so...
>>
>> Any ideas how to ensure the user has selected something from both options
>> (without javascript)?
>>
>> I couldn't find anything in the manual but assume I'm looking in all the
>> wrong places for this.

>
>
> Give the option a value 0 (well, it's more transparant/reliably checked
> then for the string 'Select one', and check if(!isset($_GET['option1']) ||
> $_GET['option1'] = 0) echo 'Please select an option.';
>
>
>
>
> Still missing something here then:
>
> page1
> <select name="this">
> <option value="0">Select one</option>
> </select>
> <select name="that">
> <option value="0">Select the other</option>
> </select>
>
>
> page2
> if (!isset($_GET['var1']) || $_GET['var1'] = "0")
> { echo 'Go back and select the first choice.'; }
>
> if (!isset($_GET['var2']) || $_GET['var2'] = "0")
> { echo 'Go back and select your second choice.'; }
>
>
> What am I missing with this please?
>
> Thanks for any help.
>
>

if (!isset($_GET['var1']) || $_GET['var1'] == "0")
{ echo 'Go back and select the first choice.'; }

if (!isset($_GET['var2']) || $_GET['var2'] == "0")
{ echo 'Go back and select your second choice.'; }

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #6 (permalink)  
Old 11-01-2007
Norman Peelman
 
Posts: n/a
Default Re: Validate variables w/out empty

pgt wrote:
> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
> news:op.t0203pi85bnjuv@metallium.lan...
> On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
>
>> I have a working couple of pages (form submits 2 variables to the second
>> page using GET).
>>
>> page1 has two dropdowns (generated from MySQL db).
>>
>> page2 retrieves info from the database accordingly, depending on the
>> passed
>> variables. Works fine.
>>
>>
>> I need to ensure that the user has actually selected both variables on
>> page1
>> from each of the drop down options on page1.
>>
>> empty() seems unable to do this because the default drop down options are
>> "Select one", "Select the other".
>>
>> so on page2, if the user has NOT made any choices:
>>
>> echo "Values passed to GET method:<br />\n";
>> reset ($_GET);
>> while (list ($key, $val) = each ($_GET)) {
>> echo "$key => $val<br />\n";
>> }
>>
>> gives me:
>> Select one
>> Select the other
>>
>>
>> I can not see how to use empty() or isset() to resolve this, so...
>>
>> Any ideas how to ensure the user has selected something from both options
>> (without javascript)?
>>
>> I couldn't find anything in the manual but assume I'm looking in all the
>> wrong places for this.

>
>
> Give the option a value 0 (well, it's more transparant/reliably checked
> then for the string 'Select one', and check if(!isset($_GET['option1']) ||
> $_GET['option1'] = 0) echo 'Please select an option.';
>
>
>
>
> Still missing something here then:
>
> page1
> <select name="this">
> <option value="0">Select one</option>
> </select>
> <select name="that">
> <option value="0">Select the other</option>
> </select>
>
>
> page2
> if (!isset($_GET['var1']) || $_GET['var1'] = "0")
> { echo 'Go back and select the first choice.'; }
>
> if (!isset($_GET['var2']) || $_GET['var2'] = "0")
> { echo 'Go back and select your second choice.'; }
>
>
> What am I missing with this please?
>
> Thanks for any help.
>
>


if (!isset($_GET['this']) || $_GET['this'] = "0")
{ echo 'Go back and select the first choice.'; }

if (!isset($_GET['that']) || $_GET['that'] = "0")
{ echo 'Go back and select your second choice.'; }


Norm
Reply With Quote
  #7 (permalink)  
Old 11-01-2007
Norman Peelman
 
Posts: n/a
Default Re: Validate variables w/out empty

Norman Peelman wrote:
> pgt wrote:
>> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
>> news:op.t0203pi85bnjuv@metallium.lan...
>> On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
>>
>>> I have a working couple of pages (form submits 2 variables to the second
>>> page using GET).
>>>
>>> page1 has two dropdowns (generated from MySQL db).
>>>
>>> page2 retrieves info from the database accordingly, depending on the
>>> passed
>>> variables. Works fine.
>>>
>>>
>>> I need to ensure that the user has actually selected both variables
>>> on page1
>>> from each of the drop down options on page1.
>>>
>>> empty() seems unable to do this because the default drop down options
>>> are
>>> "Select one", "Select the other".
>>>
>>> so on page2, if the user has NOT made any choices:
>>>
>>> echo "Values passed to GET method:<br />\n";
>>> reset ($_GET);
>>> while (list ($key, $val) = each ($_GET)) {
>>> echo "$key => $val<br />\n";
>>> }
>>>
>>> gives me:
>>> Select one
>>> Select the other
>>>
>>>
>>> I can not see how to use empty() or isset() to resolve this, so...
>>>
>>> Any ideas how to ensure the user has selected something from both
>>> options
>>> (without javascript)?
>>>
>>> I couldn't find anything in the manual but assume I'm looking in all the
>>> wrong places for this.

>>
>>
>> Give the option a value 0 (well, it's more transparant/reliably checked
>> then for the string 'Select one', and check
>> if(!isset($_GET['option1']) ||
>> $_GET['option1'] = 0) echo 'Please select an option.';
>>
>>
>>
>>
>> Still missing something here then:
>>
>> page1
>> <select name="this">
>> <option value="0">Select one</option>
>> </select>
>> <select name="that">
>> <option value="0">Select the other</option>
>> </select>
>>
>>
>> page2
>> if (!isset($_GET['var1']) || $_GET['var1'] = "0")
>> { echo 'Go back and select the first choice.'; }
>>
>> if (!isset($_GET['var2']) || $_GET['var2'] = "0")
>> { echo 'Go back and select your second choice.'; }
>>
>>
>> What am I missing with this please?
>>
>> Thanks for any help.
>>
>>

>

if (!isset($_GET['this']) || $_GET['this'] == "0")
{ echo 'Go back and select the first choice.'; }

if (!isset($_GET['that']) || $_GET['that'] == "0")
{ echo 'Go back and select your second choice.'; }

'==' fixed...

Norm
Reply With Quote
  #8 (permalink)  
Old 11-01-2007
pgt
 
Posts: n/a
Default Re: Validate variables w/out empty


"Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
news:YZ-dndstE9gcrLTanZ2dnUVZ_qXinZ2d@comcast.com...
> pgt wrote:
>> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
>> news:op.t0203pi85bnjuv@metallium.lan...
>> On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
>>
>>> I have a working couple of pages (form submits 2 variables to the second
>>> page using GET).
>>>
>>> page1 has two dropdowns (generated from MySQL db).
>>>
>>> page2 retrieves info from the database accordingly, depending on the
>>> passed
>>> variables. Works fine.
>>>
>>>
>>> I need to ensure that the user has actually selected both variables on
>>> page1
>>> from each of the drop down options on page1.
>>>
>>> empty() seems unable to do this because the default drop down options
>>> are
>>> "Select one", "Select the other".
>>>
>>> so on page2, if the user has NOT made any choices:
>>>
>>> echo "Values passed to GET method:<br />\n";
>>> reset ($_GET);
>>> while (list ($key, $val) = each ($_GET)) {
>>> echo "$key => $val<br />\n";
>>> }
>>>
>>> gives me:
>>> Select one
>>> Select the other
>>>
>>>
>>> I can not see how to use empty() or isset() to resolve this, so...
>>>
>>> Any ideas how to ensure the user has selected something from both
>>> options
>>> (without javascript)?
>>>
>>> I couldn't find anything in the manual but assume I'm looking in all the
>>> wrong places for this.

>>
>>
>> Give the option a value 0 (well, it's more transparant/reliably checked
>> then for the string 'Select one', and check if(!isset($_GET['option1'])
>> ||
>> $_GET['option1'] = 0) echo 'Please select an option.';
>>
>>
>>
>>
>> Still missing something here then:
>>
>> page1
>> <select name="this">
>> <option value="0">Select one</option>
>> </select>
>> <select name="that">
>> <option value="0">Select the other</option>
>> </select>
>>
>>
>> page2
>> if (!isset($_GET['var1']) || $_GET['var1'] = "0")
>> { echo 'Go back and select the first choice.'; }
>>
>> if (!isset($_GET['var2']) || $_GET['var2'] = "0")
>> { echo 'Go back and select your second choice.'; }
>>
>>
>> What am I missing with this please?
>>
>> Thanks for any help.
>>
>>

> if (!isset($_GET['var1']) || $_GET['var1'] == "0")
> { echo 'Go back and select the first choice.'; }
>
> if (!isset($_GET['var2']) || $_GET['var2'] == "0")
> { echo 'Go back and select your second choice.'; }
>



Arrh - Comparison operator :-)
Thanks very much all.

It's appreciated.




Reply With Quote
  #9 (permalink)  
Old 11-01-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Validate variables w/out empty

pgt wrote:
> "Jerry Stuckle" <jstucklex@attglobal.net> wrote in message
> news:YZ-dndstE9gcrLTanZ2dnUVZ_qXinZ2d@comcast.com...
>> pgt wrote:
>>> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
>>> news:op.t0203pi85bnjuv@metallium.lan...
>>> On Wed, 31 Oct 2007 23:01:45 +0100, pgt <pgtnot@gmail.not> wrote:
>>>
>>>> I have a working couple of pages (form submits 2 variables to the second
>>>> page using GET).
>>>>
>>>> page1 has two dropdowns (generated from MySQL db).
>>>>
>>>> page2 retrieves info from the database accordingly, depending on the
>>>> passed
>>>> variables. Works fine.
>>>>
>>>>
>>>> I need to ensure that the user has actually selected both variables on
>>>> page1
>>>> from each of the drop down options on page1.
>>>>
>>>> empty() seems unable to do this because the default drop down options
>>>> are
>>>> "Select one", "Select the other".
>>>>
>>>> so on page2, if the user has NOT made any choices:
>>>>
>>>> echo "Values passed to GET method:<br />\n";
>>>> reset ($_GET);
>>>> while (list ($key, $val) = each ($_GET)) {
>>>> echo "$key => $val<br />\n";
>>>> }
>>>>
>>>> gives me:
>>>> Select one
>>>> Select the other
>>>>
>>>>
>>>> I can not see how to use empty() or isset() to resolve this, so...
>>>>
>>>> Any ideas how to ensure the user has selected something from both
>>>> options
>>>> (without javascript)?
>>>>
>>>> I couldn't find anything in the manual but assume I'm looking in all the
>>>> wrong places for this.
>>>
>>> Give the option a value 0 (well, it's more transparant/reliably checked
>>> then for the string 'Select one', and check if(!isset($_GET['option1'])
>>> ||
>>> $_GET['option1'] = 0) echo 'Please select an option.';
>>>
>>>
>>>
>>>
>>> Still missing something here then:
>>>
>>> page1
>>> <select name="this">
>>> <option value="0">Select one</option>
>>> </select>
>>> <select name="that">
>>> <option value="0">Select the other</option>
>>> </select>
>>>
>>>
>>> page2
>>> if (!isset($_GET['var1']) || $_GET['var1'] = "0")
>>> { echo 'Go back and select the first choice.'; }
>>>
>>> if (!isset($_GET['var2']) || $_GET['var2'] = "0")
>>> { echo 'Go back and select your second choice.'; }
>>>
>>>
>>> What am I missing with this please?
>>>
>>> Thanks for any help.
>>>
>>>

>> if (!isset($_GET['var1']) || $_GET['var1'] == "0")
>> { echo 'Go back and select the first choice.'; }
>>
>> if (!isset($_GET['var2']) || $_GET['var2'] == "0")
>> { echo 'Go back and select your second choice.'; }
>>

>
>
> Arrh - Comparison operator :-)
> Thanks very much all.
>
> It's appreciated.
>
>
>
>
>


Don't know how many times I've done this over the past 20+ years -
probably average at least once a week :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:08 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0