Jump to content

Recommended Posts

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!

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;
?>

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?

My first question is about departments:

  1. butcher shop
  2. Fruit
  3. Department sausage / cheese cutter (Delicatessen)
  4. fish market
  5. Packaged food and cleaning

 

Then i have 5 questions for each departments:

 

For the butcher shop i have the folow questions

  1. The meat was fresh - i name it meet1
  2. The meat quality was - i name it meet2
  3. The butcher serve you well on that you needed - i name it meet3
  4. The butcher gave you advice about baking - i name it meet4
  5. 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!

  • 3 weeks later...

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;
?>

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.

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.