Probably Simple: Empty regular expression && Missing arg. 3?
Posted: Mon May 12, 2008 8:49 pm
Ok *sighs* so I'm finally at the point where I'm effectively using a single function to apply regex filters to columns of values in order to validate all the POST data before I implode it and save it to a cookie.
Visually when you create the file below you should see five columns; the first column (row 0) being the CSS selector, second it's background-color, third it's background-image (without the '.gif'), third it's border-color, and fourth it's text color.
Each row is effectively a new CSS selector and it's associated values as I just described above.
So further along towards the bottom I'm trying to visually validate using a function. I'm passing three parameters to the function: the regex filter, the value (the value of the key in the for each loop in regards to the POST array), and the POST name's ending string (number). 0$=selector, 1$=bg-color, 2$=bg-image, 3$=bg-color, 4$=text color as I stated above.
So I've commented out three calls to the function until I've gotten things a bit more in order. I currently see two errors which I'm having a bit of difficulty with...
Visually when you create the file below you should see five columns; the first column (row 0) being the CSS selector, second it's background-color, third it's background-image (without the '.gif'), third it's border-color, and fourth it's text color.
Each row is effectively a new CSS selector and it's associated values as I just described above.
So further along towards the bottom I'm trying to visually validate using a function. I'm passing three parameters to the function: the regex filter, the value (the value of the key in the for each loop in regards to the POST array), and the POST name's ending string (number). 0$=selector, 1$=bg-color, 2$=bg-image, 3$=bg-color, 4$=text color as I stated above.
So I've commented out three calls to the function until I've gotten things a bit more in order. I currently see two errors which I'm having a bit of difficulty with...
...and...Warning: Missing argument 3 for validate_clientside_array(), called on line 173 and defined on line 153
So uh, help help I'm being repressed!Warning: preg_match() [function.preg-match]: Empty regular expression on line 161
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>PHP Serverside Validation of CSS post data</title><style type="text/css">body,html {font-family: monospace;}b {color: #00f;}b.bad {color: #f00;}b.good {color: #0f0;}div.overflow {height: 200px; overflow: auto; width: 40%;}form {width: 400px;}form input {font-size: 10px; width: 60px;}</style></head><body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"><fieldset><div><input name="ce000" value="body" /><input name="ce001" value="fff" /><input name="ce002" value="ff0" /><input name="ce003" value="00f" /><input name="ce004" value="00f" /></div><div><input name="ce010" value="h2, h2, h3, h4" /><input name="ce011" value="transparent" /><input name="ce012" value="none" /><input name="ce013" value="1f" /><input name="ce014" value="1f" /></div><div><input name="ce020" value="div" /><input name="ce021" value="3f6" /><input name="ce022" value="4f6" /><input name="ce023" value="5f6" /><input name="ce024" value="5f6" /></div><div><input name="ce030" value="span" /><input name="ce031" value="7d6" /><input name="ce032" value="" /><input name="ce033" value="" /><input name="ce034" value="" /></div><div><input name="ce040" value="" /><input name="ce041" value="" /><input name="ce042" value="" /><input name="ce043" value="" /><input name="ce044" value="" /></div><div><input name="ce050" value="" /><input name="ce051" value="" /><input name="ce052" value="" /><input name="ce053" value="" /><input name="ce054" value="" /></div><div><input name="ce060" value="" /><input name="ce061" value="" /><input name="ce062" value="" /><input name="ce063" value="" /><input name="ce064" value="" /></div><div><input name="ce070" value="" /><input name="ce071" value="" /><input name="ce072" value="" /><input name="ce073" value="" /><input name="ce074" value="" /></div><div><input name="ce080" value="" /><input name="ce081" value="" /><input name="ce082" value="" /><input name="ce083" value="" /><input name="ce084" value="" /></div><br style="clear: both;" /><!--<label for="position" style="border: #000 dotted 1px; font-size: 18px;">Choose Regex Position: <select id="position" name="position"> <option value="all">Display all form names and values.</option> <option value="0">Name value ends with '0'.</option> <option value="1">Name value ends with '1'.</option> <option value="2">Name value ends with '2'.</option> <option value="3">Name value ends with '3'.</option></select></label>--><input style="display: block; width: 60%;" type="submit" value="Validate Form Data" /></fieldset></form> <div><?phpif ($_SERVER['REQUEST_METHOD'] == 'POST') {$comma_separated = implode("?", $_POST);echo '<p><b>Imploded Post Data:</b> '.$comma_separated.'</p>'."\n";} echo '<div class="overflow">';//$regex_a = '/^(([a-f0-9]{3})|([a-f0-9]{6}))$/';$regex_0_selectors = '/([0-9a-z])/';$regex_1_colors = '/^(([0-9a-f]{1,2}){3}|transparent)?$/';$regex_1_bgimages = '/^(([0-9a-f]{1,2}){3}|none)?$/'; function validate_clientside_array($regex, $var, $position){$item = '/'.$position.'$/'; foreach($_POST as $key => $value) if (preg_match($item, $key)) {echo $key."=".$value.'<br />'."\n";} //if ($validity != '1' && $key != 'ce002') { if (preg_match($regex, $var)) {echo '<b class="good">'.$key.' = '.$var.'</b> is a <b class="good">match</b>!</b><br />'."\n";} else {echo '<b class="bad">'.$key.' == '.$var.'</b> not a <b class="bad">match</b>!</b><br />';} // return false;} } return true;}// if (preg_match("/^abc/", $string) validate_clientside_array($regex_0_selectors,$value,'0');//validate_clientside_array($regex_1_colors,$value,'1');//validate_clientside_array($regex_1_colors,$value,'3');//validate_clientside_array($regex_1_colors,$value,'4'); if(!validate_clientside_array($regex_a,$value)) {$validity = '1';} echo '</div>';if (isset($validity)) {echo '<br />The array <b class="bad">contains invalid data</b>!';}else {echo '<br />The array contains <b class="good">only valid data</b>.';}?><p>Valid data includes 'transparent', short-hand hexidecimal (fff, 0ff, 123, etc), and regular hexidecimal values.</p> <p>Any other data <b><i>should</i></b> trigger an error and in which case all the form data should be rejected as a whole!</p> </div></body></html>