You are here: Re: Validate variables w/out empty « PHP Programming Language « IT news, forums, messages
Re: Validate variables w/out empty

Posted by Jerry Stuckle on 11/01/07 01:52

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
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация