Giter Club home page Giter Club logo

Comments (4)

mzur avatar mzur commented on May 30, 2024

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.

mattanddesign avatar mattanddesign commented on May 30, 2024

Thanks! I'll let you know how I get on with it.

from kirby-uniform.

mattanddesign avatar mattanddesign commented on May 30, 2024

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.

mzur avatar mzur commented on May 30, 2024

Great work! Glad to see it in action :-)

from kirby-uniform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.