I am working on a module and stuck. I have a form, but when using the post method - it redirects to the wrong page. I know it probably has something to dowith the way the page is being displayed, but I do not know what to do to fix it. below is my code:
function getBlockCode_InitialContactReview()
{
$sContent = '';
switch (bx_get('cf_clients_contacts_filter')) {
case 'add_contact':
$sContent = $this->getBlockCode_AddContact ();
break;
case 'all_contacts':
$sContent = $this->getBlockCode_AllContacts ();
break;
default:
$sContent = $this->getBlockCode_InitialContact ();
}
$sBaseUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . "view/" . $this->aDataEntry['uri'];
$aMenu = array(
_t('_cf_clients_block_submenu_initial_contact') => array('href' => $sBaseUrl, 'active' => !bx_get('cf_clients_contacts_filter')),
_t('_cf_clients_block_submenu_add_contact') => array('href' => $sBaseUrl . '&cf_clients_contacts_filter=add_contact', 'active' => 'add_contact' == bx_get('cf_clients_contacts_filter')),
_t('_cf_clients_block_submenu_all_contacts') => array('href' => $sBaseUrl . '&cf_clients_contacts_filter=all_contacts', 'active' => 'all_contacts' == bx_get('cf_clients_contacts_filter')),
);
return array($sContent, $aMenu, '', '');
}
function getBlockCode_AllContacts ()
{
$lContacts = mysql_query("SELECT * FROM cf_clients_contacts WHERE author_id = '" . $_COOKIE['memberID'] . "' AND client_id = '" . $this->aDataEntry['uri'] . "' ORDER BY date DESC");
while ($row = mysql_fetch_array($lContacts)) {
$Contacts.= '<tr style="cursor:pointer;" onclick="showPopupAnyHtml (\'modules/ccf/clients/view_contact.php/' . $row["client_contact_id"] . '\');"><td>' . $row["date"] . '</td><td>' . $row["client_contact_id"] . '</td></tr>';
}
$aVars = array (
'contacts' => $Contacts,
'page_title' => _t('_cf_clients_all_contacts'),
'client_id' => $this->aDataEntry['uri'],
);
return $this->_oTemplate->parseHtmlByName('block_contacts', $aVars);
}
function getBlockCode_InitialContact ()
{
$aAppt = $GLOBALS['MySQL']->getOne("SELECT start FROM cf_clients_appointments WHERE client_id = '" . $this->aDataEntry['uri'] . "' ORDER BY start ASC");
$aVars = array (
'page_title' => _t('_cf_clients_initial_contact_report'),
'addictions' => $this->aDataEntry['addictions'],
'date' => $this->aDataEntry['date'],
'appt' => $aAppt,
'PresentingProblem' => $this->aDataEntry['categories'],
'Location' => $this->aDataEntry['client_location'],
'SIComments' => $this->aDataEntry['si_comments'],
'block_id' => $BlockId,
'HIComments' => $this->aDataEntry['hi_comments'],
'DangerComments' => $this->aDataEntry['danger'],
'Psychosis' => $this->aDataEntry['psychotic_symptoms'],
'CapacityYN' => $this->aDataEntry['capacity'],
'CapacityComment' => $this->aDataEntry['capacity_comments'],
'ContractForSafety' => $this->aDataEntry['contract_for_safety'],
'SafetyPlanComments' => $this->aDataEntry['safety_plan'],
'med_note' => $this->aDataEntry['medications'],
'KnownMed' => $this->aDataEntry['general_health'],
'treatment_comments' => $this->aDataEntry['prior_treatments'],
'client' => $this->aDataEntry['uri'],
'FirstName' => $this->aDataEntry['client_first_name'],
'LastName' => $this->aDataEntry['client_last_name'],
'InsuranceIssues' => $this->aDataEntry['insurance_issues'],
'comments' => $this->aDataEntry['comments'],
'client_phone' => $this->aDataEntry['client_best_phone1'],
'emergency_name' => $this->aDataEntry['emergency_contact_name'],
'emergency_number' => $this->aDataEntry['emergency_contact_phone'],
'bx_if:alone' => array (
'condition' => $this->aDataEntry['is_client_caller'] == 'Yes',
'content' => array (
'FirstName' => $this->aDataEntry['client_first_name'],
'LastName' => $this->aDataEntry['client_last_name'],
),
),
'bx_if:appointment' => array (
'condition' => $aAppt != '',
'content' => array (
'appt' => $aAppt,
'FirstName' => $this->aDataEntry['client_first_name'],
'LastName' => $this->aDataEntry['client_last_name'],
),
),
'bx_if:noappt' => array (
'condition' => $aAppt == '',
'content' => array (
'FirstName' => $this->aDataEntry['client_first_name'],
'LastName' => $this->aDataEntry['client_last_name'],
),
),
'bx_if:notalone' => array (
'condition' => $this->aDataEntry['is_client_caller'] == 'No',
'content' => array (
'FirstName' => $this->aDataEntry['client_first_name'],
'LastName' => $this->aDataEntry['client_last_name'],
'WhoIsHelping' => $this->aDataEntry['who_is_caller'],
),
),
);
return $this->_oTemplate->parseHtmlByName('block_initial_contact', $aVars);
}
function getBlockCode_AddContact ()
{
bx_import('BxDolCategories');
$oCategories = new BxDolCategories();
$aRelationship = $GLOBALS['MySQL']->getOne("SELECT `relationship_status` FROM cf_clients_main WHERE uri = '" . $this->aDataEntry['uri'] . "'");
$aForm = array(
'form_attrs' => array(
'name' => 'form_add_contact',
'method' => 'post',
),
'params' => array (
'db' => array(
'table' => 'cf_clients_contacts',
'key' => 'client_contact_id',
'uri' => 'client_id', // uri field name
'submit_name' => 'submit_form',
),
'csrf' => array(
'disable' => false,
),
),
'inputs' => array(
'header_info' => array(
'type' => 'block_header',
'caption' => _t('_cf_clients_form_header_info')
),
'client_id' => array(
'type' => 'hidden',
'name' => 'client_id',
'caption' => _t('_cf_clients_form_caption_client_id'),
'value' => $this->aDataEntry['uri'],
'db' => array (
'pass' => 'Xss',
),
),
'is_client_caller' => array(
'type' => 'select',
'values' => array (
'Yes' => 'Yes',
'No' => 'No',
),
'name' => 'is_client_caller',
'caption' => _t('_cf_clients_form_caption_is_client_caller'),
'db' => array (
'pass' => 'Xss',
),
),
'who_is_caller' => array(
'type' => 'text',
'name' => 'who_is_caller',
'caption' => _t('_cf_clients_form_caption_client_who_is_caller'),
'db' => array (
'pass' => 'Xss',
),
),
'header_info_end' => array(
'type' => 'block_end'
),
// assistance
'header_assistance' => array(
'type' => 'block_header',
'caption' => _t('_cf_clients_form_header_assistance'),
),
'categories' => $oCategories->getGroupChooser ('cf_clients', (int)$iProfileId, true),
'general_health' => array(
'type' => 'text',
'name' => 'general_health',
'caption' => _t('_cf_clients_form_caption_general_health'),
'db' => array (
'pass' => 'Xss',
),
),
'medications' => array(
'type' => 'text',
'name' => 'medications',
'caption' => _t('_cf_clients_form_caption_medications'),
'db' => array (
'pass' => 'Xss',
),
),
'addictions' => array(
'type' => 'text',
'name' => 'addictions',
'caption' => _t('_cf_clients_form_caption_addictions'),
'db' => array (
'pass' => 'Xss',
),
),
'prior_treatments' => array(
'type' => 'text',
'name' => 'prior_treatments',
'caption' => _t('_cf_clients_form_caption_prior_treatments'),
'db' => array (
'pass' => 'Xss',
),
),
'insurance_issues' => array(
'type' => 'text',
'name' => 'insurance_issues',
'caption' => _t('_cf_clients_form_caption_insurance_issues'),
'db' => array (
'pass' => 'Xss',
),
),
'header_assistance_end' => array(
'type' => 'block_end'
),
// safety issues
'header_safety_issues' => array(
'type' => 'block_header',
'caption' => _t('_cf_clients_form_header_safety_issues'),
),
'si_comments' => array(
'type' => 'text',
'name' => 'si_comments',
'caption' => _t('_cf_clients_form_caption_si_comments'),
'db' => array (
'pass' => 'Xss',
),
),
'hi_comments' => array(
'type' => 'text',
'name' => 'hi_comments',
'caption' => _t('_cf_clients_form_caption_hi_comments'),
'db' => array (
'pass' => 'Xss',
),
),
'danger' => array(
'type' => 'text',
'name' => 'danger',
'caption' => _t('_cf_clients_form_caption_danger'),
'db' => array (
'pass' => 'Xss',
),
),
'psychotic_symptoms' => array(
'type' => 'text',
'name' => 'psychotic_symptoms',
'caption' => _t('_cf_clients_form_caption_psychotic_symptoms'),
'db' => array (
'pass' => 'Xss',
),
),
'contract_for_safety' => array(
'type' => 'select',
'values' => array (
'Yes' => 'Yes',
'No' => 'No',
),
'name' => 'contract_for_safety',
'caption' => _t('_cf_clients_form_caption_contract_for_safety'),
'db' => array (
'pass' => 'Xss',
),
),
'capacity' => array(
'type' => 'select',
'values' => array (
'Yes' => 'Yes',
'No' => 'No',
),
'name' => 'capacity',
'caption' => _t('_cf_clients_form_caption_capacity'),
'db' => array (
'pass' => 'Xss',
),
),
'capacity_comments' => array(
'type' => 'text',
'name' => 'capacity_comments',
'caption' => _t('_cf_clients_form_caption_capacity_comments'),
'db' => array (
'pass' => 'Xss',
),
),
'safety_plan' => array(
'type' => 'text',
'name' => 'safety_plan',
'caption' => _t('_cf_clients_form_caption_safety_plan'),
'db' => array (
'pass' => 'Xss',
),
),
'author_id' => array(
'type' => 'text',
'name' => 'author_id',
'value' => $_COOKIE['memberID'],
'caption' => _t('_cf_clients_form_caption_author_id'),
'db' => array (
'pass' => 'Xss',
),
),
'client_location' => array(
'type' => 'text',
'name' => 'client_location',
'caption' => _t('_cf_clients_form_caption_client_location'),
'db' => array (
'pass' => 'Xss',
),
),
'comments' => array(
'type' => 'text',
'name' => 'comments',
'caption' => _t('_cf_clients_form_caption_comments'),
'db' => array (
'pass' => 'Xss',
),
),
'service_type' => array(
'type' => 'select',
'name' => 'service_type',
'values' => array (
'Pending' => 'Pending',
'Individual' => 'Individual',
'Group' => 'Group',
'Family' => 'Family',
),
'caption' => _t('_cf_clients_form_caption_service_type'),
'db' => array (
'pass' => 'Xss',
),
),
'relationship_status' => array(
'type' => 'select',
'name' => 'relationship_status',
'value' => $aRelationship,
'values' => array (
'' => '',
'Single' => 'Single',
'Married' => 'Married',
'Divorced' => 'Divorced',
'In a Relationship' => 'In a Relationship',
),
'caption' => _t('_cf_clients_form_caption_relationship_status'),
'required' => true,
'db' => array (
'pass' => 'Xss',
),
),
'header_safety_issues_end' => array(
'type' => 'block_end'
),
'Submit' => array (
'type' => 'submit',
'name' => 'submit_form',
'value' => _t('_Submit'),
'colspan' => true,
),
),
);
$oForm = new BxTemplFormView ($aForm);
$oForm->initChecker();
if ($oForm->isSubmittedAndValid ()) {
// add additional vars to database, in this case creation date field is added
$aValsAdd = array (
);
if ($oForm->insert ($aValsAdd)) {
$sStatusText = '_cf_clients_assignments_updated';
}
if($sStatusText) {
$sStatusText = MsgBox(_t($sStatusText), 3);
}
return $sStatusText . $oForm->getCode();
} else
{
$aVars = array (
'form' => $oForm->getCode(),
'page_title' => _t('_cf_clients_all_contacts'),
'client_id' => $this->aDataEntry['uri'],
);
return $this->_oTemplate->parseHtmlByName('block_form', $aVars);
}