Hello @ all
I want to share a new module with you, which makes the creation and validation of forms easy. Take a look at the following example of a simple contact form:
// A very simple example of a contactform for demonstration purposes
$form = new Form('contactform');
$gender = new Select('gender');
$gender->setLabel('Gender');
$gender->addOption('Mister', '0');
$gender->addOption('Miss', '1');
$form->add($gender);
$surname = new InputText('surname');
$surname->setLabel('Surname');
$surname->setRule('required');
$form->add($surname);
$name = new InputText('name');
$name->setLabel('Name');
$name->setRule('required');
$form->add($name);
$email = new InputText('email');
$email->setLabel('E-Mail');
$email->setRule('required');
$form->add($email);
$subject = new InputText('subject');
$subject->setLabel('Subject');
$subject->setRule('required');
$form->add($subject);
$message = new Textarea('message');
$message->setLabel('Message');
$message->setRule('required');
$form->add($message);
$privacy = new InputCheckbox('privacy');
$privacy->setLabel('I accept the privacy policy');
$privacy->setRule('required')->setCustomMessage('You have to accept our privacy policy');
$form->add($privacy);
$button = new Button('submit');
$button->setAttribute('value', 'Send');
$form->add($button);
if($form->isValid()){
print_r($form->getValues());
// do what you want
}
// render the form
echo $form->render();
This piece of code creates a simple contact form and validates it according to the validation rules set. Inside the isValid() method you can run your code (fe sending an email)
Highlights:
30+ validation types
Support for UiKit 3 and Bootstrap 5 CSS framework
SPAM protection
Highly customizable
Hookable methods for further customization
Multi-language
You can download and find really extensive information on how to use at https://github.com/juergenweb/FrontendForms.
Please report errors or suggestions directly in GitHub.
Best regards and happy testing ?
If you have downloaded the module in the past I recommend you to uninstall the module completely and install the newest version 2.1.14. There are a lot of changes in the new version, so please test carefully.