HandyMail - Main class.
The main class handles generating the form HTML, running the validation and sending the email.
| package |
HandyMail |
|---|---|
| author |
I.G Laghidze developer@firewind.co.uk |
__construct(string $name, string $action, string $submit = "Submit") : null
stringSets the form name.
stringSets the URL for the action attribute for the form. Can be relative/absolute.
stringSet the submit text for the submit button. "Submit" by default.
null
add_field( $field_id, string $field_type, string $label = "", array $params = array()) : null
stringA field type from "text", "password", "email", "date", "select", "textarea", "radio", "checkbox".
stringThe field label. Optional.
arrayOptional field parameters within an associative array. The following keys are parsed:
null
authenticate_fields(array &$array) : array
This is protection against field injection, and to make sure no field names within the form have been altered. The same number of inputs must be submitted as the number of defined fields.
| access |
private |
|---|
arrayReference array (usually post) of all received inputs.
arrayReturns an array of errors. If they are empty, the validation has passed.
encode_response(array $errors) : null
arraynull
forbidden_keyword_check(array &$array) : array
| access |
private |
|---|
arrayReference array (usually post) of all received inputs.
arrayReturns an array of errors. If they are empty, the validation has passed.
generate(boolean $html_display = false) : string
booleanIf true, this returns the HTML code of the form in
tags for further customization.
stringThe form HTML code, wrapped in
tags if $html_display is set to boolean true.
get_scripts(boolean $html_display = false) : string
booleanIf true, this returns the code in
tags for further customization.
stringThe Javascript / jQuery code.
prepare_mail(array|\str $recipient, string $from, string $subject = "", string $template = "") : null
Generates the body content in both HTML (via the template) and plain-text form.
array|\strThe email recipient(s). Can be an array of recipients or a single string with a recipient email address.
stringThe email name for the from field. Will have the server name automatically appended [name]@server.tld.
stringThe subject field.
stringFilename of the template to use. This template must exist within the templates directory. Defaults to "default.php".
null
run_validation(boolean $semantic = false) : array
This is the only method you should run to validate inputs. Automatically checks the global $_POST array for the submitted form. If form validation passes, the method applies filters and appends the filtered values to their corresponding field ids defined within the $fieldsets property. If applicable, additionally populates $email_params["reply_to"] with email fields having an active "reply_to" parameter.g
booleanIf true, returns an array of fieldsets containing the field submissions. If false this returns a simple array containing [$field_id] => $value.
arrayAn array tuple containing ($boolean, $data). If $boolean is false, $data is an array of encountered errors. If $boolean is true, $data returns the validated and filtered submissions in a format dependent on $semantic.
send_mail() : array
arrayReturns an array of errors. If they are empty, the email has been successfully sent.
set_alert_classes(array $params) : null
arrayParseable keys: "success", "waiting", "error".
null
set_classes(array $params) : null
arrayParseable keys: "form", "helper", "fieldset", "fieldset_sub", "fieldset_label", "fieldbox", "field", "submit", "checkbox", "radio".
null
set_error_classes(array $params) : null
arrayParseable keys: "fieldbox", "field_label", "field_feedback".
null
set_fieldset_label(integer $gr_id, string $name) : null
integerID of the revelant fieldset group - must be previously defined through add_field.
stringLabel for the fieldset.
null
set_filters( $filters) : null
The full list of available filters is as follows: "strip_html|escape_html|trim|hash|nl2br" These are all applied recursively regardless of whether the input is an array or not.
null
set_forbidden_keywords(string $words) : null
Forbidden keywords need to be delimited with ",".
stringString of delimited forbidden words which will be appended to the current blacklist array.
null
set_input_prefix(string $input) : null
This is used to prevent clashes from ambiguities arising from matching IDs.
stringThe input prefix.
null
set_rules( $rule_array) : null
The full list of available rules is as follows: "required|numeric|alphanumeric|limit{x}|valid_email|match{x}|forbidden{x,y,z}" These are all applied recursively regardless of whether the input is an array or not.
null
set_style_profile(string $name = "default") : null
stringThe style profile name. Default by default.
null
use_captcha(string $secret, string $sitekey) : null
stringThe secret code for Google ReCaptcha
stringThe assigned sitekey from Google ReCaptcha.
null
use_smtp(array $parameters) : null
arrayThese are the SMTP parameters which are merged with the $smtp property. The following array elements are parsed:
null
valid_signature(array &$array) : array
Also removes captcha/honeypot input from the array to prevent being included in the processed results.
| access |
private |
|---|
arrayReference array (usually post) of all received inputs.
arrayReturns an array of errors. If they are empty, the validation has passed.
xss_rescue() : null
null
version
| var |
|---|
name : string
| var |
|---|
string
input_prefix : string
Prevents clashes of ID, name and classes by applying the prefix to all form elements.
| var |
|---|
string
form_action : string
| var | |
|---|---|
| access |
private |
string
submit_value : string
| var | |
|---|---|
| access |
private |
string
default_params : array
| access |
private |
|---|---|
| var |
array
xss : boolean
| var |
|---|
boolean
honeypot_name : string
| var | |
|---|---|
| access |
private |
string
forbidden_keywords : array
| var | |
|---|---|
| access |
private |
array
main_class : array
| var | |
|---|---|
| access |
private |
array
error_class : array
| var | |
|---|---|
| access |
private |
array
alert_class : array
| var | |
|---|---|
| access |
private |
array
email_params : array
| var | |
|---|---|
| access |
private |
array
mail_prepare : boolean
| var | |
|---|---|
| access |
private |
boolean
use_smtp : boolean
| var | |
|---|---|
| access |
private |
boolean
smtp : array
| var | |
|---|---|
| access |
private |
array