Get Field Value for Zebra Form' ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $zebra_form_field_number , '$zebra_form_field_number' ) ; // if ( $zebra_form_field_details['form_field_name'] === 'question_disabled' ) { // // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( // $zebra_form_field_details , // '$zebra_form_field_details' // ) ; // // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( // $zebra_form_field_indices_of_checkbox_type_zebra_form_fields , // '$zebra_form_field_indices_of_checkbox_type_zebra_form_fields' // ) ; // // } //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $_GET , '$_GET' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $_POST , '$_POST' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $adding_editing , '$adding_editing' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $the_record , '$the_record' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $the_records_index , '$the_records_index' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $array_storage_field_details , '$array_storage_field_details' ) ; //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $new_record_default_data , '$new_record_default_data' ) ; // ------------------------------------------------------------------------- // \greatKiwi_byFernTec_adSwapper_local_v0x1x210_standardDatasetManager\ // get_field_value_for_zebra_form( // $home_page_title , // $caller_apps_includes_dir , // $all_application_dataset_definitions , // $dataset_slug , // $selected_datasets_dmdd , // $dataset_title , // $dataset_records , // $record_indices_by_key , // $question_adding , // $zebra_form_field_number , // $zebra_form_field_details , // $the_record , // $the_records_index , // $array_storage_field_slugs , // $zebra_form_definition , // $key_field_slug , // $adding_editing , // $array_storage_field_details , // $zebra_form_field_indices_of_checkbox_type_zebra_form_fields , // $zebra_form_field_indices_of_radios_type_zebra_form_fields , // $new_record_default_data // ) // - - - - - - - - - - - - - - - - - - - - - - - // Returns the field value to go in the form we're creating. // // We get this field value as follows:- // // o If the form HAS been submitted, then we use the // submitted value (from $_POST). // // o If the form HASN'T been submitted, then... // // -- If the dataset has a:- // "get_default_record_data()" // // function - AND the required field exists in the // record data returned by that function - then we // use that value. // // -- Otherwise, we use the value specified by:- // + "form_field_value_from" // // NOTE! // ===== // + "form_field_value_from" can // be any of the following:- // // 1. Method: array-storage-value-from // Instance: // -------------------------------------------------------- // Use the value specified by the specified array storage // field's "array_storage_value_from" variable. // // See:- // File: add-edit-record_submission-handler-support.php // Function: get_array_storage_field_value() // for full details (of the "array_storage_value_from" // variable). // // 2. Method: array-storage-field-value // Instance: // -------------------------------------------------------- // Use the current value of the specified array storage // field. // // 3. Method: literal // Instance: // -------------------------------------------------------- // Use the specified value. // // 4. Method: function // Instance: // Args: // -------------------------------------------------------- // Use the value returned by the specified function. // // RETURNS // o On SUCCESS! // - - - - - - // array( // $ok = TRUE , // $field_value // ) // // o On FAILURE! // - - - - - - // array( // $ok = FALSE , // $error_message STRING // ) // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // Here we should have (eg):- // // $zebra_form_field_details = Array( // [form_field_name] => pathspec // [zebra_control_type] => text // [label] => Pathspec // [attributes] => Array() // [rules] => Array( // [required] => Array( // [0] => error // [1] => Field is required // ) // ) // [form_field_value_from] => Array( // [add] => Array( // [method] => literal // [args] => // ) // // [edit] => Array( // [method] => array-storage-field-slug // [args] => pathspec // ) // ) // [type_specific_args] => Array() // [constraints] => Array() // ) // // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // Here we should have (eg):- // // o If ADDING a Record // $the_record = NULL // $new_record_default_data = // o NULL - if the dataset has NO // "get_default_record_data() routine // o array(...) - if the dataset HAS a // "get_default_record_data() routine // // o If EDITING a Record // $the_record = array(...) // $new_record_default_data = NULL // ------------------------------------------------------------------------- // ========================================================================= // Init. the local variables used (to make the code clearer)... // ========================================================================= $ns = __NAMESPACE__ ; $fn = __FUNCTION__ ; // ------------------------------------------------------------------------- $success = TRUE ; $failure = FALSE ; // ========================================================================= // Ignore the Zebra Form controls that have no "default value"... // // NOTE! // ===== // Zebra Form controls with NO default value are (eg):- // o submit // o button // ========================================================================= if ( in_array( $zebra_form_field_details['zebra_control_type'] , get_zebra_controls_with_no_default_value() , TRUE ) ) { return array( $success , NULL ) ; // The returned value is a dummy value which is ignored. } // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // If the form HAS been submitted, then we get the field value from the // submitted value... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $_POST , '$_POST' ) ; if ( count( $_POST ) > 0 ) { // ===================================================================== // Is the FORM FIELD NAME in $_POST ? // ===================================================================== if ( ! array_key_exists( $zebra_form_field_details['form_field_name'] , $_POST ) ) { // ================================================================= // NO! // ================================================================= if ( $zebra_form_field_details['zebra_control_type'] === 'checkbox' ) { // ------------------------------------------------------------- // If the field is a CHECKBOX, this is OK. // // It just means that the checkbox WASN'T checked:- // ==> field value = FALSE // ------------------------------------------------------------- return array( $success , FALSE ) ; // ------------------------------------------------------------- } elseif ( $zebra_form_field_details['zebra_control_type'] === 'radios' ) { // ------------------------------------------------------------- // If the field is a RADIO GROUP, it's also OK. // // It just means that NO radio button has been checked:- // ==> field value = '' // ------------------------------------------------------------- return array( $success , '' // Ie; NO value is currently selected ) ; // ------------------------------------------------------------- } // ----------------------------------------------------------------- // For any other field type, we have a:- // No "" // error... // ----------------------------------------------------------------- $msg = << enabled // [zebra_control_type] => checkbox // [label] => Enabled ? // [help_text] => You can permanently disable this Gadget (eg; because it's under development, buggy, or no longer needed), if you want to. // [attributes] => Array() // [rules] => Array() // [type_specific_args] => Array( // [defaults_checked] => 1 // ) // [form_field_value_from] => Array( // [add] => Array( // [method] => literal // [args] => // ) // [edit] => Array( // [method] => array-storage-field-slug // [args] => enabled // ) // ) // [constraints] => Array() // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $zebra_form_field_details ) ; // ----------------------------------------------------------------- // The DEFAULT checkbox value is "1"... // ----------------------------------------------------------------- $expected_value = '1' ; // ----------------------------------------------------------------- // If another checkbox value was specified (in the form definition), // then get/check it... // ----------------------------------------------------------------- if ( array_key_exists( 'type_specific_args' , $zebra_form_field_details ) && is_array( $zebra_form_field_details['type_specific_args'] ) && array_key_exists( 'value' , $zebra_form_field_details['type_specific_args'] ) ) { // ------------------------------------------------------------- if ( ! is_string( $zebra_form_field_details['type_specific_args']['value'] ) ) { // --------------------------------------------------------- $safe_field_name = htmlentities( $zebra_form_field_details['form_field_name'] ) ; $msg = << ERROR! // ------------------------------------------------------------- $msg = << SUCCESS! // ----------------------------------------------------------------- return array( $success , TRUE ) ; // ----------------------------------------------------------------- } // ===================================================================== // NORMAL field (other than a CHECKBOX) - that WAS submitted in // $_POST... // // ==> field value = submitted value // ===================================================================== return array( $success , $_POST[ $zebra_form_field_details['form_field_name'] ] ) ; // --------------------------------------------------------------------- } // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // If the form HASN'T been submitted, then we FIRST try getting the field // value from the custom DEFAULT RECORD (if one was specified)... // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: if ( is_array( $new_record_default_data ) ) { // --------------------------------------------------------------------- // If the requested field is in the default record data, return // it's value... // --------------------------------------------------------------------- if ( array_key_exists( $zebra_form_field_details['form_field_name'] , $new_record_default_data ) ) { // ----------------------------------------------------------------- return array( $success , $new_record_default_data[ $zebra_form_field_details['form_field_name'] ] ) ; // ----------------------------------------------------------------- } // --------------------------------------------------------------------- // Otherwise, fall through to get the default value that's specified // by the Zebra Form Fields "form_field_value_from" variable... // --------------------------------------------------------------------- } // ========================================================================= // If the form HASN'T been submitted // AND // There was NO DEFAULT RECORD (or there was a default record - but NO // value for current array storage field was specified in it) // THEN // We get the field value from the Zebra Form field's // "form_field_value_from" // variable... // ========================================================================= // ------------------------------------------------------------------------- // Here we should have (eg):- // // $zebra_form_field_details['form_field_value_from'] = array( // // 'add' => array( // 'method' => 'array-storage-value-from' // 'instance' => // ) // // Use the value specified by the specified // // field's "array-storage-value-from" variable. // // -OR- // // array( // 'method' => 'literal' // 'instance' => // ) // // Use the specified value. // // -OR- // // array( // 'method' => 'function' // 'instance' => ' // 'args' => // ) // // Use the value returned by the specified // // function. // // NOTE! // ----- // array( // 'method' => 'array-storage-field-value' // 'instance" => // ) // ISN'T allowed when adding. Because by definition, // there's NO existing field value to retrieve. // // 'edit' => array( // 'method' => 'array-storage-value-from' // 'instance' => // ) // // Use the value specified by the specified // // field's "array-storage-value-from" variable. // // -OR- // // array( // 'method' => 'array-storage-field-value' // 'instance" => // ) // // Use the specified field's existing value. // // -OR- // // array( // 'method' => 'literal' // 'instance' => // ) // // Use the specified value. // // -OR- // // array( // 'method' => 'function' // 'instance' => ' // 'args' => // ) // // Use the value returned by the specified // // function. // // ) // // ------------------------------------------------------------------------- //\greatKiwi_byFernTec_adSwapper_local_v0x1x210_testDebug\pr( $zebra_form_field_details ) ; // ------------------------------------------------------------------------- if ( $question_adding ) { $add_edit = 'add' ; } else { $add_edit = 'edit' ; } // ------------------------------------------------------------------------- $method_and_args = $zebra_form_field_details['form_field_value_from'][ $add_edit ] ; //pr( $method_and_args ) ; // ------------------------------------------------------------------------- if ( $method_and_args['method'] === 'array-storage-value-from' ) { // ===================================================================== // METHOD = ARRAY-STORAGE-VALUE-FROM // ===================================================================== // --------------------------------------------------------------------- // $method_and_args = array( // 'method' => 'array-storage-value-from' // 'instance' => // ) // // Use the value specified by the specified // // field's "array-storage-value-from" variable. // --------------------------------------------------------------------- // --------------------------------------------------------------------- // "instance" specified ? // --------------------------------------------------------------------- if ( ! array_key_exists( 'instance' , $method_and_args ) ) { // ----------------------------------------------------------------- $msg = <<( // "array_storage_record_structure" => array( // => array( // "array_storage_value_from" => array(...) // ) // ) // ) // // --- // // Where "array_storage_value_from" can have the following values (as of // 23 September 2014):- // // array( // 'method' => 'created-server-datetime-utc' // ) // // array( // 'method' => 'last-modified-server-datetime-utc' // ) // // array( // 'method' => 'created-server-micro-datetime-utc' // ) // // array( // 'method' => 'last-modified-server-micro-datetime-utc' // ) // // array( // 'method' => 'unique-key' // ) // // array( // 'method' => 'literal' , // 'instance' => // ) // // array( // 'method' => 'get' , // 'instance' => '' // ) // // array( // 'method' => 'post' , // 'instance' => '' // ) // // array( // 'method' => 'server' , // 'instance' => '' // ) // // array( // 'method' => 'cookie' , // 'instance' => '' // ) // // array( // 'method' => 'function' , // 'instance' => '' , // 'args' => // ) // // --- // // RETURNS:- // // o On SUCCESS! // - - - - - - // array( // $ok = TRUE , // $field_value (any PHP type) , // $question_change // ) // NOTE! // ----- // If $question_change is anything but TRUE, then the array // storage field SHOULDN'T be updated with the returned // $field_value. For example, if you're editing a record // identified by some unique "key", then that "key" field // should never (usually) be updated. It's a unique // identifier for the record - assigned when the record is // first created - and remaining unchanged till the record // is destroyed. // // o On FAILURE! // - - - - - - // array( // $ok = FALSE , // $error_message STRING // ) // ------------------------------------------------------------------------- $result = get_array_storage_field_value( $home_page_title , $caller_apps_includes_dir , $all_application_dataset_definitions , $dataset_slug , $selected_datasets_dmdd , $zebra_form_definition , $dataset_title , $dataset_records , $record_indices_by_key , $key_field_slug , $question_adding , $adding_editing , $array_storage_field_details , $zebra_form_field_indices_of_checkbox_type_zebra_form_fields , $zebra_form_field_indices_of_radios_type_zebra_form_fields ) ; // --------------------------------------------------------------------- $ok = $result[0] ; // --------------------------------------------------------------------- if ( $ok ) { list( $ok , $field_value , $question_change ) = $result ; } else { list( $ok , $error_message ) = $result ; } // --------------------------------------------------------------------- if ( $ok === FALSE ) { return array( $failure , $err_message ) ; } // --------------------------------------------------------------------- // SUCCESS // --------------------------------------------------------------------- return array( $success , $field_value ) ; // --------------------------------------------------------------------- } elseif ( $method_and_args['method'] === 'array-storage-field-value' ) { // ===================================================================== // METHOD = ARRAY-STORAGE-FIELD-VALUE // ===================================================================== // --------------------------------------------------------------------- // $method_and_args = array( // 'method' => 'array-storage-field-value' // 'instance" => // ) // // Use the specified field's existing value. // --------------------------------------------------------------------- // --------------------------------------------------------------------- // Only valid when editing... // // Because when adding (a record), there is by definition, no existing // record to get the existing field value from). // --------------------------------------------------------------------- if ( $question_adding ) { // ----------------------------------------------------------------- $msg = << 'literal' // 'instance' => // ) // // Use the specified value. // --------------------------------------------------------------------- // --------------------------------------------------------------------- // "instance" specified ? // --------------------------------------------------------------------- if ( ! array_key_exists( 'instance' , $method_and_args ) ) { // ----------------------------------------------------------------- $msg = << 'function' // 'instance' => ' // 'args' => // ) // // Use the value returned by the specified // // function. // // Ab=nd this seems to be the new version:- // // $method_and_args = array( // 'method' => 'function' // 'instance' => array( // 'function_name' => ' // 'extra_args' => // ) // ) // // Use the value returned by the specified // // function. // --------------------------------------------------------------------- // --------------------------------------------------------------------- // "instance" specified ? // --------------------------------------------------------------------- if ( ! array_key_exists( 'instance' , $method_and_args ) ) { // ----------------------------------------------------------------- $msg = <<( // $home_page_title , // $caller_apps_includes_dir , // $all_application_dataset_definitions , // $dataset_slug , // $selected_datasets_dmdd , // $dataset_title , // $dataset_records , // $record_indices_by_key , // $question_adding , // $zebra_form_field_number , // $zebra_form_field_details , // $the_record , // $the_records_index , // $array_storage_field_slugs , // $extra_args // ) // - - - - - - - - - - - - - - - - - - - - - - - // Returns the specified field's value (for display in a Zebra Forms // based "add/edit record" form). // // NOTE! // ----- // $the_record and $the_records_index are both NULL when // $question_adding is TRUE // // RETURNS // o On SUCCESS! // - - - - - - // array( // $ok = TRUE , // $field_value // ) // // o On FAILURE! // - - - - - - // array( // $ok = FALSE , // $error_message STRING // ) // ------------------------------------------------------------------------- return $fn( $home_page_title , $caller_apps_includes_dir , $all_application_dataset_definitions , $dataset_slug , $selected_datasets_dmdd , $dataset_title , $dataset_records , $record_indices_by_key , $question_adding , $zebra_form_field_number , $zebra_form_field_details , $the_record , $the_records_index , $array_storage_field_slugs , $extra_args ) ; // --------------------------------------------------------------------- } else { // ===================================================================== // ERROR // ===================================================================== $msg = <<