Comments (4)
Sure, but you have to implement a new action as "preprocessor" for the existing email action:
uniform::$actions['email-select'] = function($form, $actionOptions) {
$recipient = $form['_recipient'];
if (!in_array($recipient, $actionOptions['allowed-recipients'])) {
return array(
'success' => false,
'message' => l::get('uniform-email-error').' Invalid recipient.'
);
}
unset($form['_recipient']);
unset($actionOptions['allowed-recipients']);
$actionOptions['to'] = $recipient;
return call_user_func(uniform::$actions['email'], $form, $actionOptions);
};
Just put the above code in a site/plugins/uniform-actions.php
file.
The action is then used just like the email
action but without the to
option. Note the new required option allowed-recipients
, too. Without checking the recipients on the server, the user would be able to send emails to arbitrary recipients.
$form = uniform(
'contact-form',
array(
'required' => array(
'_from' => 'email'
),
'actions' => array(
array(
'_action' => 'email-select',
'sender' => '[email protected]',
'subject' => $site->title()->html() . ' - message from the contact form',
'allowed-recipients' => array(
'[email protected]',
'[email protected]'
)
)
)
)
);
Finally, add the _recipient
select field to your form:
<select name="_recipient" id="_recipient">
<?php $value = $form->value('_recipient') ?>
<option value="[email protected]"<?php e($value=='[email protected]', ' selected')?>>General enquiry</option>
<option value="[email protected]"<?php e($value=='[email protected]', ' selected')?>>Marketing</option>
</select>
I've not tested all this, so tell me if you encounter any errors.
That's a pretty good idea by the way. I'll add it to the other proposed actions.
from kirby-uniform.
Thanks! I'll let you know how I get on with it.
from kirby-uniform.
Worked like a charm, thanks!
I did make one adjustment though:
'allowed-recipients' => array(
'[email protected]' => 'general',
'[email protected]' => 'marketing'
)
Meant I could get away without having the emails as plain text on the page.
You can see it live at https://skedgo.com/contact
from kirby-uniform.
Great work! Glad to see it in action :-)
from kirby-uniform.
Related Issues (20)
- Invalid CSRF token question HOT 3
- Without redirection errors accumulate over time when form is submitted multiple times HOT 3
- Incompatibility with Kirby 3.6 : Str::template() parameters deprecated HOT 2
- Custom classes HOT 1
- Choose Date Format for Form Fields HOT 3
- PHP Deprecated htmlspecialchars(): Passing null to paramete HOT 4
- Plugin is not moved by `getkirby/composer-installer` HOT 3
- Post/Redirect/Get not working HOT 1
- Character "&" gets "&" HOT 2
- Bug with Honeypots guard and the autocomplete attribute HOT 2
- RCP: "done" closure HOT 5
- Allow body in email action HOT 6
- Distinguish between validation errors and server/action errors HOT 2
- Creation of dynamic property Uniform\Actions\EmailSelectAction::$data is deprecated HOT 1
- Error on form submission after update to PHP 8.1 HOT 2
- Option for a custom message in guards HOT 1
- [K4] Issue with form submission
- [K4] 4.0 Compatibility HOT 9
- Plugin not moved to plugins folder HOT 3
- Translations not working properly HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kirby-uniform.