Error Saving CSS Colors on Settings Page
-
Hey guys,
First off I want to say Search Everything is a great plugin. Thanks for
your work on it.We did discover a couple issues though. (I’ll open a separate thread for the other one as it’s a different issue altogether.)
On the plugin settings page, if you enter a CSS color in the “Highlight Background Color” option, and use all caps (like your example), you get this error message:
Oops, there are errors in your submit:
- field Highlight Background Color should be a css color (‘red’ or ‘#abc123’)
Please go back and check your settings again.
Ironically, if you type in the CSS color used in the example below the input box…”#FFF984″, it will not work, and you get the error message.
It looks like you’re forcing all entries to be lowercase or they won’t validate. That is not the best way to validate CSS…you should be using case insensitive matching or lowercase the CSS input value in PHP before you test it.
We put together a fix, and it’s not many lines of code that need to change.
In
options.php
line 110, you have:if(!preg_match("/$rule/", $_POST[$field])) {
which uses case-sensitive matching. You don’t want case-sensitive matching, so that needs to include the
i
modifier. It should be:if(!preg_match("/$rule/i", $_POST[$field])) {
In
options.php
on line 98 you have this:"color" => "^(([a-z]+)|(#[0-9a-f]{2,6}))$",
which should be changed to this:
"color" => "^(([a-fA-F]+)|(#[0-9a-fA-F]{2,6}))$",
The regex rules do need further fixing though, as they don’t accommodate for valid 3 digit hex color values like #FFF. To fix that you would need something like this:
"color" => "^(([a-fA-F]+)|#([0-9a-fA-F]{3}){1,2})$",
Even so, the regex rules still need further fixing, because they don’t properly validate the 140 named colors – it currently allows random lowercase words that are not valid colors. To do that, you will need to add the following line after line 96:
$named_colors = array('aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightsteelblue', 'lightyellow', 'lime', 'limegreen', 'linen', 'magenta', 'maroon', 'mediumaquamarine', 'mediumblue', 'mediumorchid', 'mediumpurple', 'mediumseagreen', 'mediumslateblue', 'mediumspringgreen', 'mediumturquoise', 'mediumvioletred', 'midnightblue', 'mintcream', 'mistyrose', 'moccasin', 'navajowhite', 'navy', 'oldlace', 'olive', 'olivedrab', 'orange', 'orangered', 'orchid', 'palegoldenrod', 'palegreen', 'paleturquoise', 'palevioletred', 'papayawhip', 'peachpuff', 'peru', 'pink', 'plum', 'powderblue', 'purple', 'red', 'rosybrown', 'royalblue', 'saddlebrown', 'salmon', 'sandybrown', 'seagreen', 'seashell', 'sienna', 'silver', 'skyblue', 'slateblue', 'slategray', 'snow', 'springgreen', 'steelblue', 'tan', 'teal', 'thistle', 'tomato', 'turquoise', 'violet', 'wheat', 'white', 'whitesmoke', 'yellow', 'yellowgreen');
Then replace line 98 (now line 99) with this:
"color" => "^(#([0-9a-f]{3}){1,2}|".implode('|',$named_colors).")$",
We tested and implemented this, and it works well.
Please fix this as soon as possible. Thank you.
– Scott
- The topic ‘Error Saving CSS Colors on Settings Page’ is closed to new replies.