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.

Archive

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

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

Accessing Custom Form Variables


Reply

4 Posts   2303 Views

Avatar
Bandit

12 November 2007 at 3:07pm (Last edited: 12 November 2007 3:08pm), Community Member, 10 Posts

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

Avatar
Matt

12 November 2007 at 3:18pm (Last edited: 12 November 2007 3:19pm), Core Development Team, 84 Posts

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.

Avatar
Kelle

12 November 2007 at 3:43pm 1 Post

Thank you, Matt =D

Avatar
Bandit

12 November 2007 at 3:44pm Community Member, 10 Posts

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