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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

Contact Us - Different Recipients


Go to End


4 Posts   2362 Views

Avatar
gakenny

Community Member, 153 Posts

12 August 2007 at 9:03pm

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

Forum Moderator, 922 Posts

12 August 2007 at 9:16pm

Edited: 12/08/2007 9:36pm

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

Community Member, 153 Posts

13 August 2007 at 12:37pm

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

Forum Moderator, 922 Posts

13 August 2007 at 12:46pm

Edited: 13/08/2007 12:47pm

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