SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1 , 2
Topic CustomHtmlForm module - success message 5256 Views

CustomHtmlForm module - success message

19 September 2011 at 12:05pm

Hello,

im testing your module in my project. Everything works fine except one thing -> after successful submission i get blank page (submitSuccess() code is working - is sending email)...
I should redirect that page? How about some success message? I see in template $CustomHtmlFormMetadata, but how to fill it please?

regards

Pali

Re: CustomHtmlForm module - success message

19 September 2011 at 6:57pm

Hello Pali,
you have to use Director::redirect() as a last call in your submitSuccess(). I usually redirect to a page that has a submit message as content.
$CustomHtmlFormMetadata should be filled automatically. With this template variable a hidden field is added to the form to prevent CSRF's.

Re: CustomHtmlForm module - success message

19 September 2011 at 10:17pm

hello Roland,

thanks for info. Creating new page in cms is a bit too much for simple success message, i think. This site will show output regardless if comming from submited form or just entered Success page URL.

I played with it and found some simple solution as follows:

protected function submitSuccess($data, $form, $formData) {
...
some mailing/db storing processing
...
$currPage = Controller::curr();
$title = _t("ContactForm.SUCCESSTITLE","Message succesfully submited");
$message = _t("ContactForm.SUCCESSMESSAGE","Thank you. We received your message and we will contact you soon.");
return $currPage->customise(array("Title" => $title, "Content" => "<p class='important'>".$message."</p>"))->renderWith('Page');
}

Re: CustomHtmlForm module - success message

20 September 2011 at 9:27am

Hello Pali,
thanks for sharing your idea. It is a good approach
if you want to avoid creating a new site tree page. If you have an own page for the success message, an author
without code knowledge can change the text. If you configure this page not to be shown in the site tree nobody will get to it unless you type the correct url.

Re: CustomHtmlForm module - success message

20 September 2011 at 9:44am

Hello,

understand. But still, your approach is a little bit tricky - i must create CMS page; this page should have specific and fixed URL (which can be changed easily by content editor with title change); when we work on same project as a team, i need to inform other people about this (of course, i can automatically generate the page, but i dont want to) and finally there is a problem with multilang sites...

If we need to create succesfull message editable in backend, i will use SiteConfig decorator.

Anyway, i like your code! Its big speedster for form generation. I need to look at your cart solution closer - seems pretty solid. Looks, that almost everything is configurable via backend - is it possible to configure more things in config files?

Best regards

Pali

Re: CustomHtmlForm module - success message

20 September 2011 at 1:29pm

Hello Pali,

identifying a page object by its url segment is indeed troublesome. In SilverCart all pages get an attribute 'IdentifierCode'. SilverCart has a lot of default pages which must be identified in the code. There is a static method PageByIdentifierCode() to call these page objects. The method does not work multilingual yet but it is a good idea to change that.
I would appreciate to hear your opinion about SilverCart. We try to make most things configurable via backend. As SilverCart has a lot of own Widgets you can even configure the layout. Once you learned about our Widget system you will like it.
Of course SilverCart offers a clear API and a solid code base.

Re: CustomHtmlForm module - success message

20 September 2011 at 4:20pm

Hello Roland,

identifierCode is good idea, i need to check it out ;)

about configuration -> im not pretty familiar with backend configuration, i like much more config files. The reason is simple -> we are working in teams (2 - 3 people per project) using GIT as repo. If config is stored in files, every member of team has same configuration. If config stored in DB, we need to share DB somehow (import/export?), what is time consuming. Same thing with new installations -> with DB config i need to configure whole shop from scratch.

Its probably point of view and about purpose of product ;)

Anyway, i created one silverstripe module which is configurable on 3 places: config file, SiteConfig or Page specific config -> https://github.com/Silvermax/maxskitter/

Pali

Re: CustomHtmlForm module - success message

20 September 2011 at 7:38pm

We often work together on SilverCart driven projects and never had problems with the backend configuration. Try it and give us your feedback.