The only big issue I have seen in CF is when the user types a wrong validation code/captcha and the form returns blank, forcing the user to rewrite everything again or just giving up.
This javascript addons solves this problem. The only place where it wont work is (obviously) with upload fields.
Enjoy🙂
diff -Nru ChronoForms-V2.3.9-J1.0-pt_BR/chronocontact.php ChronoForms V2.3.9 J1.0-rsd2/chronocontact.php
--- ChronoForms-V2.3.9-J1.0-pt_BR/chronocontact.php 2008-08-30 01:42:24.000000000 -0300
+++ ChronoForms V2.3.9 J1.0-rsd2/chronocontact.php 2008-08-26 11:13:30.000000000 -0300
@@ -143,6 +143,62 @@
$htmlstring = str_replace($match,$match.' class="'.$class_string.'"',$htmlstring);
}
}
+
+ if (!empty($posted))
+ {
+ $htmlstring .= "\n<script type=\"text/javascript\"><!-- \n";
+ foreach ($posted as $post_key => $post_value)
+ {
+ if (empty($post_value)) continue;
+ $stripped_value = addslashes($post_value);
+
+ //Correct for proper javascript identification
+ $old_post_key = $post_key;
+ if (is_array( $posted[$post_key] ))
+ $post_key .= "[]";
+
+ $htmlstring .= 'chrono_field = document.ChronoContact_'.$formname.'.elements[\''.addslashes($post_key).'\'];'."\n";
+
+ $htmlstring .= "if (chrono_field) {\n";
+ $htmlstring .= " if (chrono_field.type == 'file'){ ;\n";
+
+ if (is_array( $posted[$old_post_key] ))
+ {
+ $htmlstring .= " } else if (chrono_field.type == 'select-multiple') {\n";
+ $htmlstring .= " for (i=0;i<chrono_field.options.length;i++) {\n";
+ foreach ($posted[$old_post_key] as $post_post_key => $post_post_value)
+ {
+ $stripped_value2 = addslashes($post_post_value);
+ $htmlstring .= " if (chrono_field.options[i].value == '" . $stripped_value2 . "')\n";
+ $htmlstring .= " chrono_field.options[i].selected = true;\n";
+ }
+ $htmlstring .= " }\n";
+ $htmlstring .= " }\n";
+ } else {
+ //simple select list
+ $htmlstring .= " } else if (chrono_field.type == 'select-one') {\n";
+ $htmlstring .= " for (i=0;i<chrono_field.length;i++) {\n";
+ $htmlstring .= " if (chrono_field[i].value == '" . $stripped_value . "')\n";
+ $htmlstring .= " chrono_field[i].selected = true;\n";
+ $htmlstring .= " }\n";
+
+ //is it an array? maybe a radio button
+ $htmlstring .= " } else if (!chrono_field.type && chrono_field.length) {\n";
+ $htmlstring .= " for (i=0;i<chrono_field.length;i++) {\n";
+ $htmlstring .= " if (chrono_field[i].value == '" . $stripped_value . "')\n";
+ $htmlstring .= " chrono_field[i].checked = true;\n";
+ $htmlstring .= " }\n";
+
+ $htmlstring .= " } else if (chrono_field.type == 'checkbox')\n";
+ $htmlstring .= " chrono_field.checked = true;\n";
+
+ $htmlstring .= " else\n";
+ $htmlstring .= " chrono_field.value = '$stripped_value';\n";
+ }
+ $htmlstring .= "}\n";
+ }
+ $htmlstring .= "\n --></script>\n";
+ }
$rows[0]->html = $htmlstring;
}
/// end validation //
@@ -195,13 +251,18 @@
if ( md5($chrono_verification ) != $_SESSION['chrono_verification'] ) {
showErrorMessage( CHRONO_WRONG_VERIFICATION );
showform($_POST);
+ //get the foccus to the verification code
+ echo "\n<script language=\"JavaScript\"><!-- \n"
+ . "document.ChronoContact_$formname.chrono_verification.value = '';\n"
+ . "document.ChronoContact_$formname.chrono_verification.focus();\n"
+ . "\n --></script>\n";
return;
- }else{
+ }else{
unset($_SESSION['chrono_verification']);
}
}
- /**
+ /**
* if $debug is true then ChronoForms will show diagnostic output
*/
$debug = $paramsvalues->debug;
@@ -227,24 +288,27 @@
if ( ($_FILES[$allowed_s2[0]]["size"] / 1024) > trim($paramsvalues->uploadmax) ) {
$fileok = false;
showErrorMessage( CHRONO_FILE_TOO_LARGE );
- exit();
+ showform($_POST);
+ return;
}
if ( ($_FILES[$allowed_s2[0]]["size"] / 1024) < trim($paramsvalues->uploadmin) ) {
$fileok = false;
showErrorMessage( CHRONO_FILE_TOO_SMALL );
- exit();
+ showform($_POST);
+ return;
}
$fn = $_FILES[$allowed_s2[0]]['name'];
$fext = substr($fn, strrpos($fn, '.') + 1);
if ( !in_array(strtolower($fext), $allowed_s3) ) {
$fileok = true;
showErrorMessage( CHRONO_FILE_WRONG_TYPE );
- exit();
+ showform($_POST);
+ return;
}
if ( $fileok ) {
$uploadedfile = handle_uploaded_files($original_name, $filename);
if ( $uploadedfile ) {
- $attachments[$allowed_s2[0]] = $uploadedfile;
+ $attachments[$allowed_s2[0]] = $uploadedfile;
}
}
}
-rsd