I'd like to suggest modifying uploadandmail() to return a boolean for success. On failure call showform.
E.g.
Note, the current uploadandmail() function needs a few small modifications to always return a value.
This would allow some server based validation to take place in the pre-email send php (or possibly the simple server validation proposed in an earlier post on this forum).
Server based validation is always necessary as there is no way of knowing whether a user has bypassed the javascript validation due to lack of javascript or malicious intent.
If implementing this it may also be sensible to separate the form parameter retrieval from the uploadandmail & showform functions. That would avoid the current code duplication. e.g.
E.g.
/**
* Main switch statement
*/
switch( $task ) {
case 'send':
if (!uploadandmail()) {
showform($posted);
}
break;
default:
showform($posted);
break;
}
Note, the current uploadandmail() function needs a few small modifications to always return a value.
This would allow some server based validation to take place in the pre-email send php (or possibly the simple server validation proposed in an earlier post on this forum).
Server based validation is always necessary as there is no way of knowing whether a user has bypassed the javascript validation due to lack of javascript or malicious intent.
If implementing this it may also be sensible to separate the form parameter retrieval from the uploadandmail & showform functions. That would avoid the current code duplication. e.g.
getChronoFormParams($formname) {
static $params = null;
if (is_null($params)) {
// current code to retrieve form configuration, populating $params
}
return $params;
}