Reputation: 1163
this is some form generation code. I would like to add a captcha or math verify. I have a captcha class construct file called captcha.php. I have used this class on more basic php forms ive written but the following was written by someone else. I was thinking I could either add another case called captcha or make a smartforms_captcha function. Any ideas?
function smartforms_form_field($type,$name,$class = '',$extra = array(),$prefill = true) {
global $sf_form,$sf_fid;
if (!empty($extra) && !is_array($extra)) parse_str($extra,$extra);
$classes = array('input_' . $type, $sf_form->field[$sf_fid][$name]);
if (!is_array($class)) $class = preg_split('#\s+#',$class);
$classes = trim(implode(' ',array_merge($classes,$class)));
$value = ($prefill) ? $sf_form->values[$sf_fid][$name] : '';
switch ($type) {
case 'text':
$autocomplete = ($extra['autocomplete'] == 'off') ? 'off' : 'on';
$format = '<input type="text" name="%1$s" id="%1$s" class="%2$s" value="%3$s" autocomplete="%4$s" />';
printf($format,$name,$classes,$value,$autocomplete);
break;
case 'textarea':
$rows = $extra['rows'];
$cols = $extra['cols'];
$format = '<textarea name="%1$s" id="%1$s" class="%2$s" rows="%3$d" cols="%4$d">%5$s</textarea>';
printf($format,$name,$classes,$rows,$cols,$value);
break;
}
}
Upvotes: 0
Views: 263
Reputation: 1839
I implemented an image captcha class which is some what secure as well... you can download and use the code and also if you find any interesting changes do let me know:
http://phphelperfunctions.blogspot.com/2010/09/ultimate-security-for-image-captcha-php.html
Upvotes: 1
Reputation: 7494
The captcha is mutch different that an input field, that's a group with two elements, one input text and one image, optionaly an button to reload image and listen captcha. Personaly I choose to create a new function.
function smartforms_captcha($name, $class = '', $extra = array(), $prefill = true) {
global $sf_form,$sf_fid;
if (!empty($extra) && !is_array($extra)) parse_str($extra,$extra);
if (!is_array($class)) $class = preg_split('#\s+#',$class);
$classes = trim(implode(' ',array_merge($classes,$class)));
// Create your markup correctly
$format = '<input type="text" name="$name" id="$name" class="$class" value="" />';
$format = '<img src="/captha.php?' . uniqid() . '" />'
}
}
Upvotes: 0