The form is complete. Please let me know if someone know a better way for the error handling in this template.
In all fields I use validation with regular expression, for example
Message (textarea)
Minimal 6 characters, start counting from the first alfanumeric character
/\W*\w([\w|\W]){5,}/
Email (input type="email")
/^([a-zA-Z0-9_\+\-\.]+)@([a-zA-Z0-9\-\.]{2,50})\.(com|eu|info|int|net|org|be|de|lu|nl|uk)$/
Min. 1 alfanumeric or _ + - . character before the @ , then the domain 2-50 alfanumeric or - . characters. Accepts only TLDs from a list.
CGBetterForms template
Code: Select all
{$fieldErr = ''}
{$otherErr = ''}
{$tempStr = ''}
{cgbf_form_errors assign='errors'}
{if !empty($errors)}
{foreach $errors as $err}
{if $otherErr == ''}
{if $err|strpos:'captcha' !== false}
{$fieldErr = $fieldErr|cat:' captcha '}
{elseif $err|strpos:'field is invalid' !== false}
{$tempStr = $err|substr:17|replace:'field is invalid':''}
{$fieldErr = $fieldErr|cat:$tempStr}
{else}
{$otherErr = $err}
{/if}
{/if}
{/foreach}
{/if}
{if $otherErr != ''}
<div class="alert alert-info">{$otherErr}</div>
{elseif $fieldErr != ''}
<div class="alert alert-info">One or more fields are not valid</div>
{/if}
<form id="form1" novalidate>
{* example email *}
<div class="form-group row bf-email{if $fieldErr|strpos:'email' !== false} bf-error{/if}">
<label for="email_0" class="col-sm-2 col-form-label">Email<span> *</span></label>
<div class="col-sm-10">
<input class="form-control form-control-sm" name="email" id="email_0" type="email" placeholder="name@provider.com">
</div>
</div>
{* captcha and submit*}
<div class="form-group row bf-submit{if $fieldErr|strpos:'captcha' !== false} bf-error{/if}">
<label for="cgbf_input_captcha" class="col-sm-2 col-form-label">Check<span> *</span></label>
<div class="col-sm-10">
<div data-cgbf-captcha></div>
<button class="btn btn-info" type="submit">Submit</button>
</div>
</div>
</form>