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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Data validation problem in form

Go to End



Community Member, 1 Post

6 March 2010 at 12:36pm

Edited: 06/03/2010 12:48pm


I and my programmer have problem with form on SilverStripe.

We've got as follows:

Select: Chose country*
Select: Chose year*
Field: Name*
Field: Phone**
Field: Mobile Phone**
Field: Email***

[SEND >]

* field is required
** only one number is required, so user can put either phone number or mobile, this field has custom formating so when user fill number like 123456789 it automatically fills like this 123-456-789
*** email is not required

We've disabled custom validation in JavaScript.

In Page.php we've got function in controller which creates form SideBarForm() which has action on SendSidebarForm().
Some fields in our form are dynamically generated and managed with JavaScript, so after user filled incorrect values in form, after clicking [send>], page is reloading and the wrong entered fields are marked red, unfortunately even if data was ok or wrong, we have blank fields again.

In SendSidebarForm function values from $data are saved to session from which another function (eg. GetName) reads it and sends it to theme

function GetName() {
    if(Session::get("SideBar-Name")) {
        $value = Session::get("SideBar-Name");
        return $value;
    } else
        return "";

It works but only when form is filled correctly. So we think that this function works only when correct data is filled.

We've also tried to reach this values by $_REQUEST i $_POST and writing them into session (e.g. functions Sidebar, init(), __construct, GetName, etc) but no luck.

Can we have this data saved in additional session, when form was filled with incorrect values?