Forums

Allow pre-email php to abort email sending

Chris..S 08 Jul, 2008
I'd like to suggest modifying uploadandmail() to return a boolean for success. On failure call showform.

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;
}
Max_admin 13 Jul, 2008
Hi Chris,

Thanks for the suggestions, but for the first one, when do you think it should return failed, and how the user will know there is a problem if form is shown again !!?

Best regards,

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Chris..S 13 Jul, 2008
[edited]

Hi,

I realise I left something out of my original message.

uploadandmail() would return false on error (essentially, !$error_found) and where the current code does a showform() and return.

Form specific "pre-send" php then has the opportunity to set $error_found and have the form redisplayed.

It is up to the form developer to code their form and the presend php in such a way as to inform the user what is going on.

e.g.
// in presend php
global $myform_message;
$myform_message = "The email could not be sent".

// in form php
global $myform_message;
// ...
<?php if (!empty($myform_message)) : ?>
<p class="alert"><?php echo $myform_message; ?></p>
<?php endif; ?>
This topic is locked and no more replies can be posted.