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

Accessing Custom Form Variables


Go to End
Reply


4 Posts   2387 Views

Avatar
Bandit

Community Member, 10 Posts

12 November 2007 at 3:07pm

Edited: 12/11/2007 3:08pm

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

Core Development Team, 84 Posts

12 November 2007 at 3:18pm

Edited: 12/11/2007 3:19pm

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

1 Post

12 November 2007 at 3:43pm

Thank you, Matt =D

Avatar
Bandit

Community Member, 10 Posts

12 November 2007 at 3:44pm

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