Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive

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

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

Contact Us - Different Recipients


Reply

4 Posts   1909 Views

Avatar
gakenny

12 August 2007 at 9:03pm Community Member, 153 Posts

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

Avatar
Sean

12 August 2007 at 9:16pm (Last edited: 12 August 2007 9:36pm), Forum Moderator, 921 Posts

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

Avatar
gakenny

13 August 2007 at 12:37pm Community Member, 153 Posts

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

Avatar
Sean

13 August 2007 at 12:46pm (Last edited: 13 August 2007 12:47pm), Forum Moderator, 921 Posts

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: [url]http://doc.silverstripe.com/doku.php?id=tutorial:3-forms[/url]. 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