Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

SilverStripe Forums » Archive » Form Help

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

Page: 1
Go to End
Author Topic: Form Help 192 Views
  • LeeUmm
    avatar
    Community Member
    336 posts

    Form Help Link to this post

    Been a long day, and I'm sure I'm missing the obvious here but I need some help.

    Contact form fields:

    $fields = new FieldSet(
    new TextField('Name', 'Your Name:'),
    new EmailField('Email', 'Your Email:'),
    new DropdownField('To', 'To:', $source = array(
    'Not Sure',
    'Name 1',
    'Name 2'
    )
    ),
    new TextareaField('Message', 'Message:', '5', '35')
    )

    In my template, I can produce the fields, but no names/labels for them. The following label shows up blank, but the input is shown. The fields are required, and if you click in the input box and click away without typing anything, I get the error message "Please fill out 'this', it is required." instead of the proper field name, it uses "this". Demo here - http://www.mcgowangroupinc.com/new/contact/

    <label for="$FormName_Email">$FormName_Email</label>
    $dataFieldByName(Email)

    Also, the dropdown field gives the user an option to pick who the email should be sent to. I have this in my doForm() function which sends the email:

          if($fields->to == 0){
             $email->to = 'email 1';
          } elseif ($fields->to == 1) {
             $email->to = 'email 2';
          } elseif ($fields->to == 2) {
             $email->to = 'email 3';
          }

    No matter which option is picked, it always sends to email 1. I've written the same thing using a switch statement with no luck either. In my email template, the variable $To produces the correct number associated in the drop down.

    I'm sure I'm missing something obvious as its been a 12+ hour day.

  • LeeUmm
    avatar
    Community Member
    336 posts

    Re: Form Help Link to this post

    The first part of my problem is due to using a custom template with the forTemplate() function. If I use a regular template, things are fine obviously. This part isn't to big of a deal and I can handle it later.

    However, I'd really like to be able to solve the 2nd part. That is having a contact form with a drop down field so users can choose where the email gets sent to. Has anybody ever done this before that has code working?

    My attempt above didn't work.

    192 Views
Page: 1
Go to Top

Currently Online: benedictporter, briansohn, mazang, shingonoide

Welcome to our latest member: pureprop

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.