<?php
global $mainframe;
// Some validation checks
if ( JRequest::getVar('password_text') != JRequest::getVar('confirm_password_text') )
return 'Sorry, your passwords do not match, please try again!';
if ( JRequest::getVar('town_text') == JRequest::getVar('city_text') )
return 'Sorry, your town must be different from your city';
// Store pre_qualification data version 1
$MyForm =& CFChronoForm::getInstance("qualification");
if($MyForm->formparams("dbconnection") == "Yes"){
$user = JFactory::getUser();
$row =& JTable::getInstance("chronoforms_qualification", "Table");
srand((double)microtime()*10000);
$inum = "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", ""));
JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );
if (!$row->bind( $post )) {
JError::raiseWarning(100, $row->getError());
}
if (!$row->store()) {
JError::raiseWarning(100, $row->getError());
}
$MyForm->tablerow["jos_chronoforms_pre_qualification"] = $row;
}
// Store pre_qualification data version 2
$database =& JFactory::getDBO();
$user = JFactory::getUser();
srand((double)microtime()*10000);
$inum = "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", ""));
JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
$database->setQuery( "INSERT INTO #__chronoforms_pre_qualification VALUES (
'' , '".JRequest::getVar('uid','', 'post', 'string', '' )."','".JRequest::getVar('recordtime','', 'post', 'string', '' )."', '".JRequest::getVar('ipaddress','', 'post', 'string', '' )."' , '".JRequest::getVar('cf_user_id','', 'post', 'string', '' )."' , '".JRequest::getVar('name_text','', 'post', 'string', '' )."' , '".JRequest::getVar('username_text','', 'post', 'string', '' )."' , '".JRequest::getVar('password_text','', 'post', 'string', '' )."' , '".JRequest::getVar('confirm_password_text','', 'post', 'string', '' )."' , '".JRequest::getVar('ni_text','', 'post', 'string', '' )."' , '".JRequest::getVar('email_text','', 'post', 'string', '' )."' , '".JRequest::getVar('telephone_text','', 'post', 'string', '' )."' , '".JRequest::getVar('house_text','', 'post', 'string', '' )."' , '".JRequest::getVar('street_text','', 'post', 'string', '' )."' , '".JRequest::getVar('town_text','', 'post', 'string', '' )."' , '".JRequest::getVar('city_text','', 'post', 'string', '' )."' , '".JRequest::getVar('county_text','', 'post', 'string', '' )."' , '".JRequest::getVar('postcode_text','', 'post', 'string', '' )."' , '".JRequest::getVar('other_benefit_text','', 'post', 'string', '' )."' , '".JRequest::getVar('check0','', 'post', 'string', '' )."' , '".JRequest::getVar('other_status_text','', 'post', 'string', '' )."' , '".JRequest::getVar('check1','', 'post', 'string', '' )."' , '".JRequest::getVar('check2','', 'post', 'string', '' )."' , '".JRequest::getVar('qualified_hidden','', 'post', 'string', '' )."' , '".JRequest::getVar('benefit_select','', 'post', 'string', '' )."' , '".JRequest::getVar('income_select','', 'post', 'string', '' )."' , '".JRequest::getVar('employment_select','', 'post', 'string', '' )."');" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>";
}
// Do qualification checks
$qualify = JRequest::getVar('qualified_hidden');
$sing_chk = JRequest::getVar('check0', array(), 'POST', 'array', 0);
if (JRequest::getVar('income_select') == "£0-£12,000"){
$qualify=1;
}
if ((JRequest::getVar('income_select') == "£12,000-£24,000" ) && !(in_array('Yes', $sing_chk))){
$qualify=1;
}
if ($qualify==1){
JRequest::setVar('qualified_hidden', '1' );
}
$sorry = 'Sorry, you do not qualify, our gyms only allow people on low incomes,<br /> our limit is £12,000 if you are single, and up to £24,000 if you are a couple.<br /><br />Please check back in a few months or sign up to our newsletter to be kept informed of any changes.';
if ($qualify != 1)
return $sorry;
?>
1) It works except for the checkboxes which get storred as "array". Can you show me how to properly store check box arrays, they are stored ok, in the chronoengine stored form table after validation.
2) Also i have seen this code in AutoGenerated Code/Data, it is much more simpler as it does not list all the fields, I tried to use it but I kept getting eval errors, how do I replace my code with this simpler version?
<?php
$MyForm =& CFChronoForm::getInstance("qualification");
if($MyForm->formparams("dbconnection") == "Yes"){
$user = JFactory::getUser();
$row =& JTable::getInstance("chronoforms_qualification", "Table");
srand((double)microtime()*10000);
$inum = "I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );
if (!$row->bind( $post )) {
JError::raiseWarning(100, $row->getError());
}
if (!$row->store()) {
JError::raiseWarning(100, $row->getError());
}
$MyForm->tablerow["jos_chronoforms_qualification"] = $row;
}
?>