17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 792 Views |
-
Help with simple form

15 September 2008 at 11:07pm Last edited: 15 September 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";
else
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.
Thankyou,
Eric -
Re: Help with simple form

16 September 2008 at 2:57am
All your values are stored in the array $source ..
Use $source['source'] to get the requested value.
| 792 Views | ||
|
Page:
1
|
Go to Top |


