From submission

Hey fiolks, I am stuck again and wondering if anyone can help me out.

 

A while back I made a module for a mental health site (using the groups module as the base). This was on a 7.1 version. I have installed 7.3.2 and am in the process of recreating the module. I am making a few changes based upon actual usage needs and a few other reasons.

 

Here is my dilemma:

First off, using a normal form layout on the BxGroupsModule page - the form is not being submitted. Here is what I have:


    function actionTriageAddGeneralHealth ()
    {
        $client = $_GET['client'];
            // Demographics Section
             
        $aForm = array(
            'form_attrs' => array(
                'name'     => 'form_general_health',               
                'method'   => 'post',
            ),

           'params' => array (
             
                    'db' => array(
                    'table' => 'cf_clients_general_health', // table name
                    'key' => 'general_health_id', // key field name
                    'uri' => '', // uri field name
                    'uri_title' => '', // title field to generate uri from
                    'submit_name' => 'submit_general_health_form',
                ),
                'csrf' => array(
                      'disable' => true,
                )
              ),
            'inputs' => array(
                'header1' => array(
                    'type' => 'block_header',
                ),
                'HeightFeet' => array(
                    'type' => 'select',
                    'name' => 'HeightFeet',
                    'value' => $HeightFeet,
                    'values' => array(
                    '' => '',
                    2 => 2,
                    3 => 3,
                    4 => 4,
                    5 => 5,
                    6 => 6,
                    7 => 7,
                    ),
                    'attrs' => array(
                    'id' => 'HeightFeet',
                    'onblur' => '',
                    ),
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,1),
                        'error' => _t('_cf_clients_height_feet_err'),
                    ),
                    'caption' => _t("_cf_clients_height_feet"),
                      'db' => array (
                        'pass' => 'Xss', 
                    ),
                ),
                'HeightInches' => array(
                    'type' => 'select',
                    'name' => 'HeightInches',
                    'value' => $HeightInches,
                    'attrs' => array(
                    'id' => 'HeightInches',
                    ),
                    'values' => array(
                    '' => '',
                    0 => 0,
                    1 => 1,
                    2 => 2,
                    3 => 3,
                    4 => 4,
                    5 => 5,
                    6 => 6,
                    7 => 7,
                    8 => 8,
                    9 => 9,
                    10 => 10,
                    11 => 11,
                    ),
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,2),
                        'error' => _t('_cf_clients_height_inches_err'),
                    ),
                    'caption' => _t("_cf_clients_height_inches"),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'Weight' => array(
                    'type' => 'text',
                    'name' => 'Weight',
                    'attrs' => array(
                    'id' => 'Weight',
                    ),
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,4),
                        'error' => _t('_cf_clients_weight_err'),
                    ),
                    'caption' => _t("_cf_clients_weight"),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'BMI' => array(
                    'type' => 'text',
                    'name' => 'BMI',
                    'attrs' => array(
                    'id' => 'BMI',
                    'readonly' => true,
                    ),
                    'caption' => _t("_cf_clients_bmi"),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'WeightOpinion' => array(
                    'type' => 'select',
                    'name' => 'WeightOpinion',
                    'caption' => _t("_cf_clients_weight_opinion"),
                    'values' => array(
                    '' => '',
                    'Too High' => 'Too High',
                    'Too Low' => 'Too Low',
                    'About Right' => 'About Right',
                    ),
                    'value' => $WeightOpinion,
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,25),
                        'error' => _t('_cf_clients_weight_opinion_err'),
                    ),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'AppetiteOpinion' => array(
                    'type' => 'select',
                    'name' => 'AppetiteOpinion',
                    'caption' => _t("_cf_clients_appetite"),
                    'values' => array(
                    '' => '',
                    'About Right' => 'About Right',
                    'Poor' => 'Poor',
                    'Excessive' => 'Excessive',
                    ),
                    'value' => $AppetiteOpinion,
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,25),
                        'error' => _t('_cf_clients_appetite_err'),
                    ),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'NutritionOpinion' => array(
                    'type' => 'select',
                    'name' => 'NutritionOpinion',
                    'caption' => _t("_cf_clients_nutrition"),
                    'values' => array(
                    '' => '',
                    'Excellent' => 'Excellent',
                    'Good' => 'Good',
                    'Fair' => 'Fair',
                    'Poor' => 'Poor',
                    ),
                    'value' => $NutritionOpinion,
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,25),
                        'error' => _t('_cf_clients_nutrition_err'),
                    ),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'SleepHours' => array(
                    'type' => 'select',
                    'name' => 'SleepHours',
                    'caption' => _t("_cf_clients_sleep_hours"),
                    'values' => array(
                    '' => '',
                    1 => 1,
                    2 => 2,
                    3 => 3,
                    4 => 4,
                    5 => 5,
                    6 => 6,
                    7 => 7,
                    8 => 8,
                    9 => 9,
                    10 => 10,
                    11 => 11,
                    12 => 12,
                    ),
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,2),
                        'error' => _t('_cf_clients_sleep_hours_err'),
                    ),
                    'value' => $SleepHours,
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'SleepHoursOpinion' => array(
                    'type' => 'select',
                    'name' => 'SleepHoursOpinion',
                    'caption' => _t("_cf_clients_sleep_is"),
                    'values' => array(
                    '' => '',
                    'About Right' => 'About Right',
                    'Too Much' => 'Too Much',
                    'Too Little' => 'Too Little',
                    ),
                    'value' => $SleepHoursOpinion,
                    'required' => true,

                    // checker params
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,255),
                        'error' => _t('_cf_clients_sleep_is_err'),
                    ),
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'SleepInterferance' => array(
                    'type' => 'textarea',
                    'name' => 'SleepInterferance',
                    'html' => true,
                    'value' => $SleepInterferance,
                    'caption' => _t("_cf_clients_sleep_interfernece"),
                    'required' => true,
                    'checker' => array (
                        'func' => 'length',
                        'params' => array(1,255),
                        'error' => _t('_cf_clients_sleep_interfernece_err'),
                    ),
                      'db' => array (
                        'pass' => 'XssHtml', 
                    ),
                ),
                'Dreams' => array(
                    'type' => 'textarea',
                    'name' => 'Dreams',
                    'html' => true,
                    'caption' => _t("_cf_clients_dreams"),
                    'value' => $Dreams,
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'KnownMed' => array(
                    'type' => 'textarea',
                    'name' => 'KnownMed',
                    'html' => true,
                    'caption' => _t("_cf_clients_known_med"),
                    'value' => $KnownMed,
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'GeneralHealth' => array(
                    'type' => 'textarea',
                    'name' => 'GeneralHealth',
                    'html' => true,
                    'caption' => _t("_cf_clients_general_health"),
                    'value' => $GeneralHealth,
                      'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'input_by' => array(
                    'type' => 'hidden',
                    'name' => 'input_by', // the same as key and database field name
                    'value' => $_COOKIE['memberID'],
                    // database params
                    'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'RecordID' => array(
                    'type' => 'hidden',
                    'name' => 'RecordID', // the same as key and database field name
                    'value' => $RecordID,
                    // database params
                    'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'client_id' => array(
                    'type' => 'hidden',
                    'name' => 'client_id', // the same as key and database field name
                    'value' => $client,
                    // database params
                    'db' => array (
                        'pass' => 'Xss',  // do XSS clear before getting this value, see BxDolFormCheckerHelper class for all pass* functions
                    ),
                ),
                'header1_end' => array(
                    'type' => 'block_end'
                ),
             'submit_send' => array(
            'type' => 'submit',
            'colspan' => true,
            'name' => 'submit_general_health_form',
            'value' => _t("_cf_clients_submit_general_health"),
        ),
             ),
        );

        $oForm = new BxTemplFormView ($aForm);
        $oForm->initChecker();


        if ($oForm->isSubmittedAndValid ()) {
            // add additional vars to database, in this case creation date field is added
             $aValsAdd = array (
                 'client_id' => $client,
             );
 
             echo 'insert last id: ' . $oForm->insert ($aValsAdd); // insert validated data to database
         }
   
    echo DesignBoxContent(_t('_cf_clients_add_general_health'), $oForm->getCode (), 11);
    }

 

Now, I am not sure if it is because of how the form is displayed or what. Basically, I have a table with a link in the upper right corner of the block to add a new General Health input. Clicking the add link opens the form in the same block that the table was in (photos attached).

 

Also, although there are required fields, if nothing is entered it still acts like it is submitting - even though it is not submitting nor is it redisplaying the form with errors listed.

 

Any help would be greatly appreciated. But once I get this issue resolved, there is a second part.

caredesign.net
Quote · 10 Aug 2016

i tried to add pics to original post, but for some reason it was taking too long.

ght page.png · 1.4M · 168 views
ght page add link.jpg · 380.3K · 172 views
ght page add block.jpg · 337.6K · 163 views
ght database.jpg · 383.1K · 171 views
caredesign.net
Quote · 10 Aug 2016

I would suggest to check if submit button is button instead of input, then you can pass some non empty hidden field in the form params:

'submit_name' => 'submit_general_health_form', 
Rules → http://www.boonex.com/terms
Quote · 11 Aug 2016

I tried that and still not like I want it. I am guessing it is because of how the page is displaying and when it tries to redirect back to same page - it reloads the original block. I will have to play around with getting what I need.

 

My second issue: I need to add javascript functions to m form. Now, Deano showed me a long time ago how to accomplish this, but it was not on the BxDroupsModules page, instead it was on the BxGroupsPageView page. This is what I have:

 

function actionTriageAddGeneralHealth ()
    {
        $client = $_GET['client'];
            // Demographics Section
           
        $myJavaScript = <<<CODE
       
        <script type="text/javascript" language="javascript">
function f_calBMI() {
    var v_heightF = document.getElementById("HeightFeet").value;
    var v_heightI = document.getElementById("HeightInches").value;
    var v_weight = document.getElementById("Weight").value;
    var v_height = 0 ;
    var v_bmi = "" ;
    if ((v_heightF != "") && (v_weight!= "") && !isNaN(v_heightF) && !isNaN(v_weight)) {
        //calculate height
        if (v_heightI != "" && !isNaN(v_heightI)) {
        v_height = parseFloat(v_heightF)*12 + parseFloat(v_heightI) ;
        }     
        else { v_height = parseFloat(v_heightF)*12 ;}         
        v_bmi = parseFloat(v_weight)*703/(v_height*v_height) ;
        v_bmi = Math.round(parseFloat(v_bmi)*10) ;
        v_bmi = v_bmi/10 ;
        document.getElementById("BMI").value = v_bmi ;
        } else {
            document.getElementById("BMI").value = "";   
            }
            }

window.onload = function() {
   
f_calBMI() ;
    document.getElementById("HeightFeet").onblur = f_calBMI ;
    document.getElementById("HeightInches").onblur = f_calBMI ;
    document.getElementById("Weight").onblur = f_calBMI ;
    document.getElementById('form1').onclick = f_calBMI ;
       
}
// -->
</script>
CODE;
        $aForm = array(
            'form_attrs' => array(
                'name'     => 'form_general_health',
                'action'   => BX_DOL_URL_ROOT . 'm/clients/triage_insert_general_health?client=' . $client,
                'method'   => 'post',
            ),
..................................................................


        $oForm = new BxTemplFormView ($aForm);
        $oForm->initChecker();


        if ($oForm->isSubmittedAndValid ()) {
            // add additional vars to database, in this case creation date field is added
             $aValsAdd = array (
                 'client_id' => $client,
             );
 
             echo 'insert last id: ' . $oForm->insert ($aValsAdd); // insert validated data to database
         }
   
    echo DesignBoxContent(_t('_cf_clients_add_general_health'), $myJavaScript . $oForm->getCode(), 11);
    }

 

I am trying to calculate the BMI of a client using a formula based on height and weight. the formula and all does work on a different page, so I know it is somewhat correct. Any help is greatly appreciated.

caredesign.net
Quote · 11 Aug 2016

ok, scratch the second issue. Instead, I just ran the calculation using php on another page right before submission to database.

caredesign.net
Quote · 11 Aug 2016
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.