sakisdem Posted November 30, 2012 Share Posted November 30, 2012 Hi to all i am trying to create a right variable so can display random questions. Let me explain feather My first question is a checkbox questions with 5 answers. every answer have a 5 more group questions. I need a variables code to do this: Every time the user checks (in first checkbox) the answer 1 and 3 the code automatically selected to display the group of 1 or 3 (not the 2 together) The same philosophy must have and the outher questions, if the answer (on first) is 2, 4 and 5 must display the group of question 2 or 4 or 5. Thanks a lot! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 30, 2012 Share Posted November 30, 2012 If the answers selected are in an array (such as $_POST['answers'] ) <?php $answers = array(2, 4, 5) ; // could be $_POST['answers'] $random_group = $answers[array_rand($answers)]; echo $random_group; ?> Quote Link to comment Share on other sites More sharing options...
sakisdem Posted November 30, 2012 Author Share Posted November 30, 2012 actialy my site is build in joomla 2.5.8 and the program i use the RSForm Pro component. All the variables is display in one php file: <?php /** * @version 1.4.0 * @package RSform!Pro 1.4.0 * @copyright © 2007-2011 www.rsjoomla.com * @license GPL, http://www.gnu.org/copyleft/gpl.html */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); class RSFormProValidations { function none($value,$extra=null,$data=null) { return true; } function alpha($param,$extra=null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false && preg_match('#([^a-zA-Z ])#', $param[$i])) return false; return true; } function numeric($param,$extra=null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if (strpos($extra,$param[$i]) === false && !is_numeric($param[$i])) return false; return true; } function alphanumeric($param,$extra = null,$data=null) { if(strpos($param,"\n") !== false) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false && preg_match('#([^a-zA-Z0-9 ])#', $param[$i])) return false; return true; } function alphaaccented($value, $extra=null, $data=null) { if (preg_match('#[^[:alpha:] ]#u', $value)) { return false; } return true; } function alphanumericaccented($value, $extra=null, $data=null) { if (preg_match('#[^[:alpha:]0-9 ]#u', $value)) { return false; } return true; } function email($email,$extra=null,$data=null) { jimport('joomla.mail.helper'); $email = trim($email); return JMailHelper::isEmailAddress($email); } function emaildns($email,$extra=null,$data=null) { // Check if it's an email address format if (!RSFormProValidations::email($email,$extra,$data)) return false; $email = trim($email); list($user, $domain) = explode('@', $email, 2); // checkdnsrr for PHP < 5.3.0 if (!function_exists('checkdnsrr') && function_exists('exec') && is_callable('exec')) { @exec('nslookup -type=MX '.escapeshellcmd($domain), $output); foreach($output as $line) if (preg_match('/^'.preg_quote($domain).'/',$line)) return true; return false; } // fallback method... if (!function_exists('checkdnsrr') || !is_callable('checkdnsrr')) return true; return checkdnsrr($domain, substr(PHP_OS, 0, 3) == 'WIN' ? 'A' : 'MX'); } function uniquefield($value, $extra=null,$data=null) { $db =& JFactory::getDBO(); $form = JRequest::getVar('form'); $formId = (int) @$form['formId']; $db->setQuery("SELECT `SubmissionValueId` FROM #__rsform_submission_values WHERE FormId='".$formId."' AND `FieldName`='".$db->getEscaped($data['NAME'])."' AND `FieldValue`='".$db->getEscaped($value)."'"); return $db->loadResult() ? false : true; } function uniquefielduser($value, $extra=null,$data=null) { $db =& JFactory::getDBO(); $form = JRequest::getVar('form'); $formId = (int) @$form['formId']; $user =& JFactory::getUser(); $db->setQuery("SELECT sv.`SubmissionValueId` FROM #__rsform_submission_values sv LEFT JOIN #__rsform_submissions s ON (sv.SubmissionId=s.SubmissionId) WHERE sv.FormId='".$formId."' AND sv.`FieldName`='".$db->getEscaped($data['NAME'])."' AND sv.`FieldValue`='".$db->getEscaped($value)."' AND (".($user->get('guest') ? "s.`UserIp`='".$db->getEscaped($_SERVER['REMOTE_ADDR'])."'" : "s.`UserId`='".(int) $user->get('id')."'").")"); return $db->loadResult() ? false : true; } function uszipcode($value) { return preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$value); } function phonenumber($value) { return preg_match("/\(?\b[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}\b/i", $value); } function creditcard($value,$extra=null,$data=null) { $value = preg_replace ('/[^0-9]+/', '', $value); if (!$value) return false; if (preg_match("/^([34|37]{2})([0-9]{13})$/", $value)) // Amex return true; if (preg_match("/^([30|36|38]{2})([0-9]{12})$/", $value)) // Diners return true; if (preg_match("/^([6011]{4})([0-9]{12})$/", $value)) // Discover return true; if (preg_match("/^([51|52|53|54|55]{2})([0-9]{14})$/", $value)) // Master return true; if (preg_match("/^([4]{1})([0-9]{12,15})$/", $value)) // Visa return true; return false; } function custom($param,$extra=null,$data=null) { if(strpos($param,"\n") !== FALSE) $param = str_replace(array("\r","\n"),'',$param); for($i=0;$i<strlen($param);$i++) if(strpos($extra,$param[$i]) === false) return false; return true; } function password($param,$extra=null,$data=null) { if ($data['DEFAULTVALUE'] == $param) return true; return false; } function ipaddress($param,$extra=null,$data=null) { return preg_match('#\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b#', $param, $match); } function validurl($param,$extra=null,$data=null) { $format = '/^(https?):\/\/'. // protocol '(([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+'. // username '([a-z0-9$_\.\+!\*\'\(\),;\?&=-]|%[0-9a-f]{2})+)?'. // password '@)?(?#'. // auth requires @ ')((([a-z0-9][a-z0-9-]*[a-z0-9]\.)*'. // domain segments AND '[a-z][a-z0-9-]*[a-z0-9]'. // top level domain OR '|((\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])\.){3}'. '(\d|[1-9]\d|1\d{2}|2[0-4][0-9]|25[0-5])'. // IP address ')(:\d+)?'. // port ')(((\/+([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)*'. // path '(\?([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)'. // query string '?)?)?'. // path and query string optional '(#([a-z0-9$_\.\+!\*\'\(\),;:@&=-]|%[0-9a-f]{2})*)?'. // fragment '$/i'; return preg_match($format, $param, $match); } function regex($value,$pattern=null,$data=null) { return preg_match($pattern, $value); } function registrationCode($param,$extra=null) { $validCodes = array('AAAA','BBBB','CCCC','DDDD'); $bul = true; foreach($validCodes as $validCode) if(strtolower($validCode) == strtolower($param)) { $bul = true; //verify if this was used before $db = &JFactory::getDBO(); $db->setQuery("SELECT `SubmissionId` FROM #__rsform_submission_values WHERE `FieldValue` = '".$param."' AND `FormId` = '".intval($_POST['form']['formId'])."' LIMIT 1"); $tmp = $db->loadResult(); if($tmp) $bul = false; //break; } else $bul = false; return $bul; }} Can you help me from here? Quote Link to comment Share on other sites More sharing options...
sakisdem Posted November 30, 2012 Author Share Posted November 30, 2012 and my questions is one by one and i need to group the question befor do anything Quote Link to comment Share on other sites More sharing options...
sakisdem Posted November 30, 2012 Author Share Posted November 30, 2012 My first question is about departments: butcher shop Fruit Department sausage / cheese cutter (Delicatessen) fish market Packaged food and cleaning Then i have 5 questions for each departments: For the butcher shop i have the folow questions The meat was fresh - i name it meet1 The meat quality was - i name it meet2 The butcher serve you well on that you needed - i name it meet3 The butcher gave you advice about baking - i name it meet4 There was good variety in terms of types of butcher - i name it meet5 etc. What to i do to make each departments questions a group & My first questions i am trying to create a right variable so can display random questions. Let me explain feather My first question is a checkbox questions with 5 answers. every answer have a 5 more group questions. I need a variables code to do this: Every time the user checks (in first checkbox) the answer 1 and 3 the code automatically selected to display the group of 1 or 3 (not the 2 together) The same philosophy must have and the outher questions, if the answer (on first) is 2, 4 and 5 must display the group of question 2 or 4 or 5. I hope to understand Thanks a lot! Quote Link to comment Share on other sites More sharing options...
sakisdem Posted December 1, 2012 Author Share Posted December 1, 2012 Can anyone help me? Plz! Quote Link to comment Share on other sites More sharing options...
sakisdem Posted December 1, 2012 Author Share Posted December 1, 2012 nobody? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2012 Share Posted December 1, 2012 I've shown you how to get a random group from the selected answers. All you need to do next is retrieve the set of questions for that group and display them. Quote Link to comment Share on other sites More sharing options...
sakisdem Posted December 1, 2012 Author Share Posted December 1, 2012 the a lot for the answer Barand but i'm really new in scripts. Can you please show me how to do that? Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2012 Share Posted December 1, 2012 Not without knowing how you are storing your groups of questions. Quote Link to comment Share on other sites More sharing options...
sakisdem Posted December 18, 2012 Author Share Posted December 18, 2012 I already do this but I don’t know if is correct… <?php $meetgroup[ ] = "meet1"; $meetgroup[ ] = "meet2"; $meetgroup[ ] = "meet3"; $meetgroup[ ] = "meet4"; $meetgroup[ ] = "meet5"; $fruitgroup[ ] = "fruit1"; $fruitgroup[ ] = "fruit2"; $fruitgroup[ ] = "fruit3"; $fruitgroup[ ] = "fruit4"; $fruitgroup[ ] = "fruit5"; $delicatgroup[ ] = "delicat1"; $delicatgroup[ ] = "delicat2"; $delicatgroup[ ] = "delicat3"; $delicatgroup[ ] = "delicat4"; $delicatgroup[ ] = "delicat5"; $fishgroup[ ] = "fish1"; $fishgroup[ ] = "fish2"; $fishgroup[ ] = "fish3"; $fishgroup[ ] = "fish4"; $fishgroup[ ] = "fish5"; $pfcgroup[ ] = "pfc1"; $pfcgroup[ ] = "pfc2"; $pfcgroup[ ] = "pfc3"; $pfcgroup[ ] = "pfc4"; $pfcgroup[ ] = "pfc5"; $answers = a1(a10, a11, a12, a13, a14) ; // could be $_POST['answers'] $random_group = $answers[array_rand($meetgroup, $fruitgroup, $delicatgroup, $fishgroup, $pfcgroup)]; echo $random_group; ?> Quote Link to comment Share on other sites More sharing options...
Barand Posted December 18, 2012 Share Posted December 18, 2012 (edited) Are you using a database a ) to store the questions? b ) to store the survey results? If not, how do you store them? Edited December 18, 2012 by Barand Quote Link to comment Share on other sites More sharing options...
sakisdem Posted December 18, 2012 Author Share Posted December 18, 2012 Actually I’m using Joomla 2.5.8 and the RSForm Pro component. The component, store all the results in one table in my database. (Created himself). Barand if you wand I can give you access to my administration panel in Joomla and see if you can help me. Quote Link to comment Share on other sites More sharing options...
Barand Posted December 18, 2012 Share Posted December 18, 2012 I have zero experience of Joomla so I couldn't be of much help there. Here's a solution using an ini-type file, but you could substitute a db solution. The main thing is the method. The questions file [0] meat="Butcher shop" fruit="Fruit" delicat="Department sausage / cheese cutter (Delicatessen)" fish="Fish market" pfc="Packaged food and cleaning" [meat] 1="The meat was fresh" 2="The meat quality was good" 3="The butcher serve you well on that you needed" 4="The butcher gave you advice about baking" 5="There was good variety in terms of types of meat" [fruit] 1="The fruit was fresh" 2="The fruit quality was good" 3="The grocer serve you well on that you needed" 4="The grocer gave you advice about baking" 5="There was good variety in terms of types of fruit" [delicat] 1="Deli question 1" 2="Deli question 2" 3="Deli question 3" 4="Deli question 4" 5="Deli question 5" [fish] 1="Fish question 1" 2="Fish question 2" 3="Fish question 3" 4="Fish question 4" 5="Fish question 5" [pfc] 1="PFC question 1" 2="PFC question 2" 3="PFC question 3" 4="PFC question 4" 5="PFC question 5" the code <?php if (isset($_POST['group'])) { if ($_POST['group']=='0') { // // initial questions so get one group at random // from the answers // $group = $_POST['answers'][array_rand($_POST['answers'])]; } else { $group = $_POST['group']; // // save group and answers to DB here // exit ("Thank you for your response"); } } else { // // nothing posted yet so display initial questions // $group = '0'; } $questionsArray = parse_ini_file('questions.txt',1); $questions = '<h3>' . $questionsArray['0'][$group] . '</h3>'; foreach ($questionsArray[$group] as $k => $q) { $questions .= "<input type='checkbox' name='answers[]' value='$k'> $q<br />\n"; } ?> <form method="post"> <input type='hidden' name='group' value="<?php echo $group?>" /> <?php echo $questions?> <br /> <input type='submit' name='btnSubmit' value='Submit' /> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.