TOPIC:

how to use a php variable inside js script 2 days 22 hours ago #254623

  • Topic Author
  • ferrari
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 16
  • Thanks: 0
well i create a php function where i change the format of dates from sql query into an array of string
(the string of every element of the array is: "2021-1-23");
at this point i have to take this php variable inside the javascript code, change into an array of dates and at the end i have to put the array of dates in disable field.

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

how to use a php variable inside js script 2 days 22 hours ago #254624

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

something like this:
  //include ('libraries/libOtp/db_conn.php');
$db = JFactory::getDBO();
$sql = "SELECT `dataApp`FROM `cons_appuntamenti` ";
$db->setQuery($sql);
$data = $db->loadObjectList();
$dataArray=array();
for ($i = 0; $i <count($data); $i++) {
  $dataArray[$i]=$data[$i]->dataApp;
  // array_push($dataArray, data[$i]->dataApp);
    //$dataArray.push($data[$i]->dataApp);
   //echo $dataArray[$i];
};

$dataArray1=changeFormat($dataArray);
var_dump($dataArray1);

//$data="SELECT `dataApp`FROM `cons_appuntamenti`;";
 //$sql=mysqli_query($connection, $data) or die(mysqli_error($connection));
//var_dump( $dataArray);
echo '<br>';
echo '<script type="text/javascript">
		JQuery(document).ready(function () {
                            
                            var arrData='.$dataArray1.';
	                    var testData = [ [2021,0,22], [2021,0,23] ]; 		
			JQuery("#ff_elem180_calendarButton").pickadate({
				format: "yyyy-mm-dd", 
				selectYears: 60,
                                disable: testData,
				selectMonths: true,
				editable: true,
				firstDay: 1,
				onSet: function() {JQuery("#ff_elem180").val(this.get("value"));}
			});
                    });
	</script>';
            

Regards,
Tihana

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

how to use a php variable inside js script 2 days 22 hours ago #254626

  • Topic Author
  • ferrari
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 16
  • Thanks: 0
i have already tried this but on the console of devTools it trews this error:



BF-Trace
<strong>*** EXCEPTION CAUGHT BY BREEZINGFORMS ***</strong>
PHP error level : E_NOTICE
PHP filename : C:\MAMP\htdocs\app-consolato\components\com_breezingforms\facileforms.process.php(1246) : eval()'d code
PHP linenumber : 23
Last known pos : Before form piece calendarSync at line 1
Error message : Array to string conversion

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

how to use a php variable inside js script 2 days 22 hours ago #254629

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

this is just a notice.

Did you get what you want?
Did you test only this:
crosstec.org/en/forums/coding-consultanc....html?start=0#254584
Is this working ?

Regards,
Tihana

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

how to use a php variable inside js script 2 days 21 hours ago #254633

  • Topic Author
  • ferrari
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 16
  • Thanks: 0
ok i solve with the following syntax:
       
       echo '<script type="text/javascript">
		JQuery(document).ready(function () {
                            
                            var data= '.json_encode($dataArray1).'; 
                            var dataFinal=[];
                            for (var i = 0; i < data.length; i++) {
                                 dataFinal[i]=new Date(data[i][0],data[i][1],data[i][2]);
    
                           }
       	                    	
			JQuery("#ff_elem180_calendarButton").pickadate({
				format: "yyyy-mm-dd", 
				selectYears: 60,
                                disable: dataFinal,
				selectMonths: true,
				editable: true,
				firstDay: 1,
				onSet: function() {JQuery("#ff_elem180").val(this.get("value"));}
			});
                    });
	</script>';
     

with this way i convert the array from php to javascript in order to create the array of dates that i use in the disable field.
Thanks for the help.

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

how to use a php variable inside js script 2 days 20 hours ago #254638

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

super!

I am glad that you solved it :)

Regards,
Tihana

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

  • Page:
  • 1
  • 2
Time to create page: 0.052 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!