help on validation before accepting user input

Status
Not open for further replies.

rongame

Member
hi guys

i hope you can help me,on how to perform validation before data being written into the database.

similar to username ajax validation during registration.

thanks so much
 
troester thanks for the reply

by the way im using joomla 3.1.1 and fabrik 3.1.b

the validation will be based on another database. i checked on the validations->actions and i dont see anything which is related to my other data.

thanks again
 
Hello,

I don't know about connecting to another database (you might need to change the way you will connect to the external database), but for validation i think you can add a php validation like this:

Code:
$value =  '{tablename___elementname}';
$db =JFactory::getDBO();
$query=("SELECT field FROM table where field = '$value'");
$db->setQuery($query);
$response = $db->loadResult();
if ($response == 'your condition') {
return true;
} else {
return false;
}
 
thanks
Please clarify
BTW im not a coder friend. Given the following
Table 1=table1 (client will encode data key in this table)
keycode=element where in client will encode a datakey which is pre generated
sample validations:
1. can not leave empty
2. keycode is invalid
3. keycode is in use
activation form=form that has the list of elements that will be encoded into the databse once key is valid
= this form can be cancelled if your keycode is in valid.
Tabele 2=table2(table where key will be checked if already in use or the key entered is not valid)
Pre Generated keys=element that has the keys.

friend where will i insert the php code? how do i accomplish the above?

thanks so much
 
I think all the validations will run before submitting the information, so just add validations to the "keycode" element. Go to the Validation Tab in element and add validations like this:

1. Notempty validation - included by default in Fabrik
2. Keycode is invalid- see the php code, if value from database: table2 = value added by user then return true else return false. To use the code, add PHP validation like in my example.
3. Also a php validation, but you have to detail what is mean "in use"? Has been already used? If yes, how you will determine this, you will register 1 for used and 0 for not used?

As i said, the form will not submit information if all validations will not meet the conditions added.
 
Oh, and here is how can you connect to external database in Joomla:


$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = ''; // Database host name
$option['user'] = ''; // User for database authentication
$option['password'] = ''; // Password for database authentication
$option['database'] = ''; // Database name
$option['prefix'] = ''; // Database prefix (may be empty)

$db = & JDatabase::getInstance( $option );

So instead of $db =JFactory::getDBO(); add all the code from above (without comments)
 
hi im getting "code does not exist" even do the code is correct. by the way im changing my requirement to just validation on tables created on fabrik and not an external database. i dont know what command should be called to make the connection.
table 1 = empenc_warranty //form table that will be used by the end user
table 2 = seak_keycode //form table that will have the keycodes
both list and forms are generated via fabrik
warranty_code = element of table 1 (user will encode) that will validate data from table 2
encrypted_keycodes = element of table 2 tha holds the keycodes.
$value = '{seak_keycode___encrypted_keycodes}'; // should this be may second table which i created using fabrik?
$db =JFactory::getDBO(); //Get a db connection.
$query=("SELECT warranty_code FROM empenc_warranty where warranty_code = '$value'"); //should the fields be from table 1
$db->setQuery($query); //Reset the query using our newly populated query object
$response = $db->loadResult();
if ($response == $value) //my condition is that $value == to $query
{
return true;
} else {
return false;
thanks
 
$option = array(); //prevent problems
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = ''; // Database host name
$option['user'] = ''; // User for database authentication
$option['password'] = ''; // Password for database authentication
$option['database'] = ''; // Database name
$option['prefix'] = ''; // Database prefix (may be empty)

$db = & JDatabase::getInstance( $option );

guys i tried the above. still nothing. when i hit save even do the code is correct the element vaidation error message is still being triggered.
 
Its not clear to me what is text and what is code in your posts, so can you format the code you are using inside the code formatter available in the forum's wysiwyg editor. e.g.
Can you also post all of the code you are using.

Code:
this is my code
 
thanks for the reply, here it is:
table 1 = empenc_warranty //db table that will be used by the end user
table 2 = seak_keycode //db table that will have the keycodesboth list and forms are generated via fabrik
warranty_code = element of table 1 (user will encode) that will validate data from table 2
encrypted_keycodes = element of table 2 tha holds the keycodes.

Code:
$value =  '{empenc_warranty___warranty_code}';
$option = array();
$option['driver'] = 'mysql';
$option['host'] = 'localhost';
$option['user'] = 'userco_game';
$option['password'] = '123456';
$option['database'] = 'neco_game';
$option['prefix'] = 'zyz1_';
$db = & JDatabase::getInstance( $option );
$query=("SELECT * FROM seak_keycode where encrypted_keycodes  = '$value' ");
$result=mysql_query($query);
if ($result == $query) {
return true;
} else {
return false;
}

by the way im no coder so im really just experimenting on the code above. i hope you can explain it so i get educated in the process.

thanks again
 
PHP:
$value =  '{empenc_warranty___warranty_code}';
$option = array();
$option['driver'] = 'mysql';
$option['host'] = 'localhost';
$option['user'] = 'userco_game';
$option['password'] = '123456';
$option['database'] = 'neco_game';
$option['prefix'] = 'zyz1_';
$db =  JDatabase::getInstance( $option );
 

// Best to use Joomla's query builder:
$query = $db->getQuery(true);
 
// Use COUNT(*) to count the # of records matched
$query->select("COUNT(*)")->from('seak_keycode');
 
// ALWAYS use $db->quote() for user inputted values - otherwise is a major security risk
$query->where('encrypted_keycodes  = ' . $db->quote($value));

// Set the query to the db
$db->setQuery($query);
 
// Run the query and return a single value (the # of records matched)
$matched = $db->loadResult();

if ($matched > 0) {
   // We found some records so return true
   return true;
} else {
  // No records found - return false.
   return false;
}
 
hi rob

still nothing, i tried to redo the list and forms but still nothing.

Code:
$value = 1;
$option = array();
$option['driver'] = 'mysql';
$option['host'] = 'localhost';

i even replaced $value with just 1 and see if it will validate but it still says validation failed.

please help.
 
hi rob
to clarify {empenc_warranty___warranty_code} = {seak_keycode___encrypted_keycodes} to continue or submit
if false
then error message "code is invalid"

thanks
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top