TOPIC:

Database Access in Action Script 3 months 3 weeks ago #257360

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6465
  • Karma: 3
  • Thanks: 457
Hi again,

I found that what you want can't be done the way you planned because it wouldn't be able to fetch the value entered in the textfield (calendar).

But there we can find alternative, maybe to populate select from list instead of radio group? Is this ok for you?

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Database Access in Action Script 3 months 3 weeks ago #257372

  • Topic Author
  • fsv_sarstedt
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 9
  • Thanks: 0
The PHP Script does not need to fetch the date from the textfield, it will get the entered date via AJAX. Here is the working Javascript Code from the Actionscript Field of the Textbox:
function ff_customcalendar_action(element, action){
    switch (action) {
        case 'change':
            console.log(ff_getElementByName('customcalendar').value)
            jQuery.ajax({
                type: "POST",
                url: "/php/test.php",
                data: {date: ff_getElementByName('customcalendar').value},
                success: function(timestring){
                    console.log("Times:" + timestring);
                    const times = timestring.split(';');
                    switch (times.length - 1) {
                        case 1:
                            generateRadioGroup( 'time', [
                                {
                                    'label' : times[1],
                                    'value' : times[1]
                                }
                            ] );
                            break;
                        case 2:
                            generateRadioGroup( 'time', [
                                {
                                    'label' : times[1],
                                    'value' : times[1]
                                },
                                {
                                    'label' : times[2],
                                    'value' : times[2]
                                }
                            ] );
                            
                            break;
                        case 3:
                            generateRadioGroup( 'time', [
                                {
                                    'label' : times[1],
                                    'value' : times[1]
                                },
                                {
                                    'label' : times[2],
                                    'value' : times[2]
                                },
                                {
                                    'label' : times[3],
                                    'value' : times[3]
                                }
                            ] );
                            break;
                    }
                } //function_msg
            }); //ajax
        break;
        default:;
    } // switch
} // ff_customcalendar_action

function generateRadioGroup(elementName, setup){

    var elementId = jQuery("input[name='ff_nm_"+elementName+"[]']:radio").closest('.bfElemWrap').attr('id').split("bfElemWrap")[1];
    var mainLabel = jQuery("#bfLabel"+elementId).html();
    var outerTemplate = '<div class="controls form-inline"><div class=" "><label class="control-label" id="bfLabel'+elementId+'" for="ff_elem'+elementId+'">#MAINLABEL#</label><span class="">#FIELDS#</span></div></div>';
    var elementTemplate = '<label style="vertical-align: baseline;" class="radio inline " id="bfGroupLabel'+elementId+'#INDEX#" for="ff_elem'+elementId+'#INDEX#"><input class="ff_elem" type="radio" name="ff_nm_#NAME#[]" value="#VALUE#" id="ff_elem'+elementId+'#INDEX#">#LABEL#</label>';
    var elementTemplateCopy = '';
    var fields = '';

    if(setup.length > 0){

        // cleaning first
        jQuery('#bfElemWrap'+elementId).html('');

        for(var i = 0; i < setup.length; i++){
            elementTemplateCopy = elementTemplate;
            elementTemplateCopy = elementTemplateCopy.replace(/#NAME#/g, elementName);
            elementTemplateCopy = elementTemplateCopy.replace(/#VALUE#/g, setup[i].value);
            elementTemplateCopy = elementTemplateCopy.replace(/#LABEL#/g, setup[i].label);
            if(i == 0){
                elementTemplateCopy = elementTemplateCopy.replace(/#INDEX#/g, '');
            }else {
                elementTemplateCopy = elementTemplateCopy.replace(/#INDEX#/g, "_"+i);
            }

            fields += elementTemplateCopy;
        }

        outerTemplate = outerTemplate.replace("#FIELDS#", fields);
        outerTemplate = outerTemplate.replace("#MAINLABEL#", mainLabel);

        jQuery('#bfElemWrap'+elementId).html(outerTemplate);
    }
}
It reads the entered date, sends it to the PHP script and expects to get back a String using the format "%data%;%time1%;%time2...". It then parses the String and populates the Radio Buttons. The only part missing here is the selection of Data from the Database which then should be formatted and returned as "%data%;%time1%;%time2..."

Please Log in or Create an account to join the conversation.

Database Access in Action Script 3 months 2 weeks ago #257403

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6465
  • Karma: 3
  • Thanks: 457
Hi,

super!

Sorry for late reply, I will check how to get back a String like:
"%data%;%time1%;%time2..." and get back to you

UPDATE: here is example how to create php file
<?php

define( '_JEXEC', 1 );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );
define( 'DS', DIRECTORY_SEPARATOR );

/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'database'.DS.'factory.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');

$code=$_POST['code'];   				// the value posted from the AJAX request above
//-----process DB query-------

$database = $db = JFactory::getDBO();

$sql="SELECT time,date FROM fsv_available_dates WHERE date='$code'";

$database->setQuery($sql);

//----------------------------

if($back=$database->loadAssoc()){    //check if query result is empty
$res=$back['time'].';'.$back['date'];
echo $res;   // send value back to Breezingforms (AJAX request of the Change)
   }
   else echo ""; // send back empty string if all DB query has no result

               
?>


Regards,
Tihana
The following user(s) said Thank You: fsv_sarstedt

Please Log in or Create an account to join the conversation.

Last edit: Post by tihana.krivic. Reason: added the code for php file

Database Access in Action Script 3 months 2 weeks ago #257409

  • Topic Author
  • fsv_sarstedt
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 9
  • Thanks: 0
Thanks alot, the script works!
Thank you for your fast support!

Please Log in or Create an account to join the conversation.

Database Access in Action Script 3 months 2 weeks ago #257417

  • tihana.krivic's Avatar
  • tihana.krivic
  • Offline
  • Moderator
  • Moderator
  • Posts: 6465
  • Karma: 3
  • Thanks: 457
Hi,

np, anytime.

If you need anything else feel free to ask :)

Regards,
Tihana

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.039 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!