So I'd like to check for an entry by a user in a table before allowing a second entry. If the user already has an entry I do not want them to have the ability to submit a second entry.
I tried creating a custom validator which I think is probably the appropriate way of doing this, but didn't have much luck. I was able to create a hook that seems to prevent the form from submitting, but I can't figure out how to output an error message that I can capture on the page.
Here is my snippet:
<?php
$path = MODX_CORE_PATH . 'components/memberdata/';
$result = $modx->addPackage('memberdata',$path.'model/','mp_');
$output = '';
$userid = $modx->user->get('id');
$company = $modx->getObject('companyProfiles',array('FK_member_id' => $userid));
if ($company) {
return false;
}
else
{
return true;
}
And my Formit call if needed:
[[!FormIt?
&hooks=`spam,checkDupCompanyUser,formit2db`
&preHooks=`db2formit`
&prefix=`mp_`
&packagename=`memberdata`
&tablename=`company_profiles`
&classname=`companyProfiles`
&validate=`
nospam:blank,
companyName:required,
FK_companytype_id:required:minLength=`1`,
FK_state_id:required:minLength=`1`,
`
&companyName.vTextRequired=`Please enter a Company Name.`
&FK_companytype_id.vTextMinLength=`Please select a Company Type.`
&FK_companytype_id.vTextRequired=`Company Type is a required field.`
&FK_state_id.vTextMinLength=`Please select a State.`
&FK_state_id.vTextRequired=`State is a required field.`
&vTextRequired=`Please enter a value for this field.`
]]
Any help as always is greatly appreciated.