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 " alert('".$database->getErrorMsg()."'); window.history.go(-1); ";}// 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, our limit is £12,000 if you are single, and up to £24,000 if you are a couple.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?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; } ?>"> Storing pre-validated froms in database - Forums

Forums

Storing pre-validated froms in database

hrhsii 13 May, 2010
I have been storing pre-validated forms in my own database table using the following ServerSide Validation code:
<?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;
		}
		?>
GreyHead 14 May, 2010
Hi hrhsii,

Why would you do this from the server-side validation box. Seems like a lot of hard work to me.

Use the servers-side validation box to validate the user's replies and nothing more.

Use the onsubmit before box to do the checks and show the answer then ChronoForms can handle the arrays and the DB save for you.

Bob
hrhsii 14 May, 2010
Thank you Bob,

I can move my qualification checks to the onsubmit before box, and do a return for any unsuccessful applicants. Then chronoForm will automatically save the qualified users into the database. That is ok, but I also need to save the unqualified users who do not automatically get saved and emailed.

I have been trying to use the code below, by changing the chronoforms_qualification to chronoforms_pre_qualification as that is the name of my database table but I get an eval error. Something about bind... Can you explain how to use this code (taken from AutoGenerated Code/Data) to save the unsuccesfully submitted data please?

<?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;
      }
      ?>
GreyHead 14 May, 2010
Hi hrhsii,

Why use separate tables at all. You could post them all to the same table but add a 'qualified' flag.

I can't explain the JTable code in a few lines - but I think that you'll find more at docs.Joomal.org

Bob
This topic is locked and no more replies can be posted.