Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ttskch/contact-form
PHP utility classes to implement general contact form
https://github.com/ttskch/contact-form
contact-form email form sendmail
Last synced: 16 days ago
JSON representation
PHP utility classes to implement general contact form
- Host: GitHub
- URL: https://github.com/ttskch/contact-form
- Owner: ttskch
- License: mit
- Created: 2018-07-17T09:08:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T12:19:36.000Z (over 5 years ago)
- Last Synced: 2024-04-22T06:43:53.559Z (7 months ago)
- Topics: contact-form, email, form, sendmail
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# contact-form
[![Travis (.com) branch](https://img.shields.io/travis/com/ttskch/contact-form/master.svg?style=flat-square)](https://travis-ci.com/ttskch/contact-form)
[![Latest Stable Version](https://poser.pugx.org/ttskch/contact-form/v/stable?format=flat-square)](https://packagist.org/packages/ttskch/contact-form)
[![Total Downloads](https://poser.pugx.org/ttskch/contact-form/downloads?format=flat-square)](https://packagist.org/packages/ttskch/contact-form)PHP utility classes to implement general contact form (also with confirmation view). It's maybe useful to build contact form on WordPress or pure PHP site.
## Requirements
* PHP 5.4+
* Configuring `date.timezone` in php.ini## Supported features
* Csrf protection with session and hidden input tag
* Server side validation for submitted values
* **Short hands to print submitted value itself, validation errors, "selected" option, "checked" option**
* Attaching files and handle them easily in the same session
* Sending email which contains submissions information easily## Installation
```bash
$ composer require ttskch/contact-form
```or
```bash
$ git clone [email protected]:ttskch/contact-form.git
$ cd contact-form
$ composer install --no-dev# If your web site is not composer-friendly, upload whole "contact-form" directory by hand.
```## Usage
```php
validateAndRedirectAfterSelfPosted('./confirm.php', $requiredKeys, $emailKeys);
?>
= $cf->csrfHiddenInput(); ?>
= $cf->presentError('Name'); ?>
= $cf->presentError('Email'); ?>
presentSelected('Gender', 'Male', $default = true); ?>>Male
presentSelected('Gender', 'Female'); ?>>Female
presentSelected('Gender', 'Other'); ?>>Other
Confirm
```
```php
rejectAccessWithoutSubmissions('./index.php');// after posted, validate csrf and redirect to next page
$cf->validateAndRedirectAfterSelfPosted('./thanks.php');
?>
= $cf->csrfHiddenInput(); ?>
= $cf->present('Name'); ?>
= $cf->present('Email'); ?>
= $cf->present('Gender'); ?>
Send
Back```
```php
rejectAccessWithoutSubmissions('./index.php');$template = <<present('Name', false),
$cf->present('Email', false),
$cf->present('Gender', false),
]);$cf->sendEmail(
'[email protected]', // to
'[email protected]', // from
'Your Name', // from name
'Got inquiry', // subject
$body // body
);// clear submissions after sending email
// by this, if users reload thanks.php after sending email they will be redirected to index.php
$cf->clearSubmissions();
?>Form is successfully submitted!
```See [demo](demo) code or run it on your local to learn more :)
### Precaution
Because this utility calls [header()](https://www.php.net/manual/en/function.header.php) function to redirect, you must execute instantiation and some methods before any actual output is sent.