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.

Form Questions

Custom validation


Reply

4 Posts   2875 Views

Avatar
Dipak

11 February 2009 at 8:58pm Community Member, 8 Posts

Hello friends,
I am using silverstripe 2.3.0 rc1

I want to use custom validation on the phone field, please guide me in the same, I want to use javascript for validation

here is code snippet

function Form() {
      return new Form($this, "Form", new FieldSet(

         // List your fields here
         new TextField("ContactPerson", "Contact Person"),
         new EmailField("Email", "Email address"),
         new DropdownField("Reason", "Your Reason", array(
"Sales" => "Sales",
"Marketing" => "Marketing")),
         new PhoneNumberField( $name = "PhoneNumber",
                        $title = "Phone Number "
                        ),
         new TextareaField( $name = "Remarks",
                        $title = "Remark",
                        $rows = 8,
                        $cols = 3)
         

      ), new FieldSet(

         // List the action buttons here
         new FormAction("SubmitAction", "Submit"),
         new ResetFormAction("ClearAction","Clear")

      ), //new CustomValidator($javascriptCode)
         
         //new CustomValidator("<script>window.open('new.html')</script>")
         //new ContactFormValidation()
         new RequiredFields("ContactPerson","Email","Reason","PhoneNumber"   )
      );
   }

reply become appreciable.
please hurry..
Thank You

Avatar
Nexus Rex

3 May 2009 at 2:24am Community Member, 8 Posts

I need help as well figuring out how to disable/enable some fields according to the state of a radio button.

Example:

Are you over 18? () Yes () No
If No:
Parent's Email: __________________________

-------------------
Why does it seem that 70% or more of good questions on this forum go unanswered? I think this forum's lack of quick user help is going to hurt SS.

Avatar
TerryMiddleton

19 May 2009 at 4:43am Community Member, 108 Posts

Hi Dipak,

Hey did you ever get the customvalidation to work with the javascript?

I have the exact same situation, but can't figure it out to save my life.

What did you end up doing?

I simply want to add to the required field validation and add a validator for a phonefield to be at least 10 digits in length.

Let me know if you solved this,

Terry

Avatar
Elemental

8 July 2009 at 8:16pm Community Member, 8 Posts

Hi Terry, Dipak,

Did you guys find a solution for that validation and your problems?

Please let me know.

thanks
angelo