Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Accessing Custom Form Variables

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

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

Page: 1
Go to End
Author Topic: 2297 Views
  • Bandit
    Avatar
    Community Member
    10 Posts

    Accessing Custom Form Variables Link to this post

    Howdy

    I've got the following code for my custom form but it is just sending an empty e-mail;

    <?php
    class EmailForm_Controller extends Page_Controller {

       function SignupForm() {
    return new Form($this, "SignupForm", new FieldSet(
    // List the your fields here
    new TextField("FirstName", "First name"),
    new TextField("Surname"),
    new EmailField("Email", "Email address")

    ), new FieldSet(
    // List the action buttons here
    new FormAction("doform", "Sign up")

    ), new RequiredFields(
    // List the required fields here: "Email", "FirstName"
    ));
    }

    function doform($data, $form) {
          
       mail("james@gooduse.co.nz", "Comments", $form->$FirstName);

    // Redirect to a page thanking people for registering
    Director::redirect('thanks-for-registering/');
    }

    }
    ?>

    At the moment you'll see I'm using $form->$FirstName as a test for the e-mail field but it's not working - what syntax should I be using?

    Cheers

    James

  • Matt
    Avatar
    Core Development Team
    84 Posts

    Re: Accessing Custom Form Variables Link to this post

    You can use either of the following:

    $data['FirstName'] // $data is an array containing the form names and values
    // OR
    $form->dataFieldByName('FirstName')->Value() // This is the form object, getting the FirstName form object, then getting that object's value.

  • Kelle
    Avatar
    1 Post

    Re: Accessing Custom Form Variables Link to this post

    Thank you, Matt =D

  • Bandit
    Avatar
    Community Member
    10 Posts

    Re: Accessing Custom Form Variables Link to this post

    Hey, it's Kelle Brickhead! (just look at her avatar)

    2297 Views
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.