Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Contact Us - Different Recipients

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1886 Views
  • gakenny
    Avatar
    Community Member
    153 Posts

    Contact Us - Different Recipients Link to this post

    Hello,

    I would like to create a Contact Us form where the sender selects the recipient from a drop down list. The email addresses will not be published to minimize SPAM to these addresses. Is there a way that I can achieve this using the standard Contact Us form. Creating a drop down list of the email addresses is easy enough but this does not achieve the desired result.

    Thanks,

    Gary

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Contact Us - Different Recipients Link to this post

    Hi gakenny,

    The contact form (UserDefinedForm class) does not support this out of the box. What you'll need to do is subclass the UserDefinedForm class.

    1. First, add this line to your _config.php file in mysite:

    Object::useCustomClass('UserDefinedForm', 'CustomUserDefinedForm');

    2. Create CustomUserDefinedForm.php within mysite/code

    3. Start with something like this in CustomUserDefinedForm.php:

    class CustomUserDefinedForm extends UserDefinedForm {

    }

    class CustomUserDefinedForm_Controller extends UserDefinedForm_Controller {

       function process() {
          // overload the function on UserDefinedForm.php like this
       }

    }

    This should get you started. I would suggest copying the contents of the process() function from UserDefinedForm.php to where the // comment is above, and modify it so it does something different when a user submits the form.

    Hope this helps!

    Sean

  • gakenny
    Avatar
    Community Member
    153 Posts

    Re: Contact Us - Different Recipients Link to this post

    Hi Sean,

    Thanks for that. I *might* leave that functionality for v2 of the site. Can I manually create a form for submission (and populating the dropdown myself) instead of using the form wizard supplied with Silverstripe?

    Thanks,

    Gary

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Contact Us - Different Recipients Link to this post

    Hi again,

    You can, and in fact, I would recommend you do this instead of overriding the UserDefinedForm class (contact form). It's a complex piece of code that's designed to allow flexibility of building forms (non-code) for any situtation. So, if you're looking for certain form requirements it's best to create your own custom form to avoid complications, you also have full control over it's behaviour.

    For some reference, you can see this tutorial on building SilverStripe forms: http://doc.silverstripe.com/doku.php?id=tutorial:3-forms. It's a basic form in the tutorial, but the principles of are exactly the same for any form in SilverStripe.

    If you need any further help, I'd be happy to help.

    Cheers,
    Sean

    1886 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.