Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Data validation problem in form

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

Page: 1
Go to End
Author Topic: 855 Views
  • lukasz
    Community Member
    1 Post

    Data validation problem in form Link to this post


    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?

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.