mzur / kirby-uniform

A versatile Kirby plugin to handle web form actions.
https://kirby-uniform.readthedocs.io
MIT License
252 stars 40 forks source link

multiple email address #103

Closed fabiooid closed 7 years ago

fabiooid commented 8 years ago

Is it possible to receive enquiries from the contact form to different email address according to what option is selected in the select field?

for example I have 3 shops, I select what shop to contact and when I press submit the email get sent to the specified shop email address?

thank you

Fabio

mzur commented 8 years ago

Check out the email-select action :wink:

fabiooid commented 8 years ago

thanks a lot for you quick reply! following the instruction I get an error though: "There was an error sending the form: Invalid recipient"

my contact form code is

<form action="<?php echo $page->url()?>#contact" method="post">
   <div class="select__outer">
     <select name="_recipient" id="_recipient">
     <?php $value = $form->value('_recipient') ?>
       <option value="city"<?php e($value=='city', ' selected')?>>City</option>
       <option value="south-yarra"<?php e($value=='south-yarra', ' selected')?>>South Yarra</option>
       <option value="docklands"<?php e($value=='docklands', ' selected')?>>Docklands</option>
     </select>
   </div>
   <input<?php e($form->hasError('name'), ' class="erroneous"')?> type="text" name="name" id="name" value="<?php $form->echoValue('name') ?>" placeholder="Name" required/>
    <input<?php e($form->hasError('_from'), ' class="erroneous"')?> type="email" name="_from" id="email" value="<?php $form->echoValue('_from') ?>" placeholder="Email" required/>
    <textarea name="message" id="message" placeholder="Message" ><?php $form->echoValue('message') ?></textarea>
     <label class="uniform__potty" for="website">Please leave this field blank</label>
     <input type="text" name="website" id="website" class="uniform__potty" />

     <a name="form"></a>
     <?php if ($form->hasMessage()): ?>
     <div class="form__message <?php e($form->successful(), 'success' , 'error')?>">
        <?php $form->echoMessage() ?>
     </div>
         <?php endif; ?>
      <button class="button--submit" type="submit" name="_submit" value="<?php echo $form->token() ?>"<?php e($form->successful(), ' disabled')?>>SUBMIT</button>
</form>

and my controllers/home.php

<?php

return function($site, $pages, $page) {

   $form = uniform(
      'contact-form',
      array(
         'required' => array(
            '_from' => 'email'
         ),
         'actions'  => array(
            array(
               '_action' => 'email',
               'sender'  => 'contactform@a25.com.au',
               'subject' => $site->title()->html() . ' - message from the contact form',
               'allowed-recipients' => array(
                  'city'     => 'fabio@test1.com',
                  'south-yarra' => 'fabio@test2.com',
                  'docklands'  => 'fabio@test3.com'
               )
            )
         )
      )

   );
   return compact('form');
};

do you have any idea why is this happening?

mzur commented 8 years ago

It should be '_action' => 'email-select' but you probably already got that (since the error message is from the email-select action), right?

Edit: I just tested it and that's the cause of the error after all. Change the action and everything should be fine.