Forum Moderators: coopster

Message Too Old, No Replies

Dual Array: For detecting invalid GET values?

If a property and value do not match to warn the user.

         

JAB Creations

3:32 am on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure what the terminology of it would be but I would like to do what I'm referring to in my head as a dual array or maybe a parallel array? I have a list of properties that can be manipulated with certain values. However I would like to detect when a GET request with a non-existent property or an invalid value occurs. I'm using CSS terminology here too so let me clarify visually...

Array Sample
property, value,

(
audio, 0,
audio, 1,
audio, 2,
bandwidth, 1,
bandwidth, 2,
browserpatch, 0,
browserpatch, 1,
dhtmleffects, 0,
dhtmleffects, 1,
dhtmlengine, 0,
dhtmlengine, 1,
dtd, t,
dtd, s,
dtd, 1,
dtd, 2,
mediatype, xx,
mediatype, ax,
mediatype, tx,
mediatype, th,
ieccss, 0,
ieccss, 1,
powerkeys, 0,
powerkeys, 1,
theme, classic,
theme, cityblue,
theme, emerald,
theme, lavender,
)

These are examples of my working properties and values. If I could keep the list like it is right now with minor modifications to get it working it would be great as I plan on adding further options in the future. However I'm not exactly sure how I should approach this.

Also this is important as I have tested invalid values and it broke the page once while being served as application/xhtml+xml so this could potentially lead to loosing visitors if I do not address this issue. Suggestions to create this error handler script?

- John

[edited by: JAB_Creations at 3:40 am (utc) on April 26, 2007]

capulet_x

5:31 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Do you mean you want to filter the values? How are these values entered through a text field, button, slider?

JAB Creations

7:11 am on Apr 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The properties are passed through the URL either from typing it or clicking a link as so...

<a href="index.php?audio=1">test</a>

If someone enters an invalid value for a property (or an invalid property) I want to be able to capture it in a sense and display a help layer to make the user aware with links to references.

- John

[edited by: JAB_Creations at 7:13 am (utc) on April 26, 2007]

capulet_x

7:27 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Can you have a drop down menu of just the valid options or is this not possible for what you are trying to accomplish?

adb64

8:23 am on Apr 26, 2007 (gmt 0)

10+ Year Member



Hi John,

Does the code below suits your needs


$Properties = array(
'audio' => array(0,1,2),
'bandwidth' => array(1,2),
...
'theme' => array('classic','cityblue','emerald','lavender')
);
foreach($_GET as $property => $value)
{
if (array_key_exists($property,$Properties))
{
if (array_search($value,$Properties[$property]) === FALSE)
{
echo "Invalid value $value for property $property\n";
}
else
{
/* here you may handle the property with a valid value */
}
}
else
{
echo "Invalid property $property\n";
}
}

BTW, I haven't tested the code above

Regards,
Arjan