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, Ed, biapar, Willr, Ingo

Help with simple form

Go to End

2 Posts   1147 Views


Community Member, 1 Post

15 September 2008 at 11:07pm

Edited: 15/09/2008 11:07pm

Hi, I am currently working on a website and am having trouble with forms.

I am attempting to create a simple quiz where the user has one question with 5 options. I have got to the stage where the form is created, but I am stuck on how to return / pass the value they have selected. Following the tutorials and documentation, I have got this so far. Basically all this is trying to do is display weather the user has selected option 1 or not, however I am not that familiar with php and am struggling to pass the value.

Any help or suggestions would be greatly appreciated.

class Quiz_Controller extends Page_Controller {

function Quiz() {
// Create fields
$fields = new FieldSet(
// List the your fields here
new OptionsetField(
$name = "Quiz1",
$title = "Test Qustion...",
$source = array(
"1" => "Option 1",
"2" => "Option 2",
"3" => "Option 3",
"4" => "Option 4",
"5" => "Option 5"

// Create actions
$actions = new FieldSet(
new FormAction('doQuiz', 'Submit')

return new Form($this, 'Quiz', $fields, $actions);

function doQuiz($source) {

if ($source=="1")
echo "Option1 selected";
echo "Option1 not selected";



Again, it is this last function, doQuiz, or more so the passing of values between the two functions, that I am struggling with.



Community Member, 791 Posts

16 September 2008 at 2:57am

All your values are stored in the array $source ..

Use $source['source'] to get the requested value.