beo77388
03-05-2010, 02:03 AM
Hello,
I wonder if you can help with this simple php form below (no db involved) and give the most elegant answer to this challenge.
I want to add a function to the submit that gets the total for the checked "yes" buttons only. Then multiply by 100 and divide by number of questions (to get %). If % is below 55% then load page http://example.com/pagex; if above 55% then load page http://example.com/pagey.
Thank you for your reply.
Code below (of the questions):
<?php
function quiz_form ($form_state) {
$form = array();
$form ['q1'] =array (
'#type' => 'radios',
'#title' => t('1. Do you like to drink coffee?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
);
$form ['q2'] =array (
'#type' => 'radios',
'#title' => t('2. Do you drink coffee every morning?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
); n/
$form ['q3'] =array (
'#type' => 'radios',
'#title' => t('3. Do you drink coffee more than once a day?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
); n/
?>
I wonder if you can help with this simple php form below (no db involved) and give the most elegant answer to this challenge.
I want to add a function to the submit that gets the total for the checked "yes" buttons only. Then multiply by 100 and divide by number of questions (to get %). If % is below 55% then load page http://example.com/pagex; if above 55% then load page http://example.com/pagey.
Thank you for your reply.
Code below (of the questions):
<?php
function quiz_form ($form_state) {
$form = array();
$form ['q1'] =array (
'#type' => 'radios',
'#title' => t('1. Do you like to drink coffee?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
);
$form ['q2'] =array (
'#type' => 'radios',
'#title' => t('2. Do you drink coffee every morning?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
); n/
$form ['q3'] =array (
'#type' => 'radios',
'#title' => t('3. Do you drink coffee more than once a day?'),
'#options' => array('first' => t('Yes'),'second' => t('No')),
'#required' => TRUE,
); n/
?>