Forum Replies Created
- AuthorPosts
Labella
ParticipantIt works! Great! Thank you
November 16, 2020 at 11:31 am in reply to: Modify a field value based on select option change #32218Labella
ParticipantThank you!
Labella
ParticipantI discover that if I put the rows in a separate jQuery(function ($) it works! I’m not so good with these things sorry! Maybe I should put each operation in a separate jQuery(function ($), I guess. Is it right?
Labella
ParticipantOf course! This is a page containing the form (you must scroll down and click on “ISCRIZIONE” in order to show it): https://www.labellaschool.it/corsi-professionali-musica/corso-di-arrangiamento-e-produzione-di-andrea-pellegrini/
I write here the entire code that I have in custom JS panel, maybe there is something wrong somewhere else! But the other forms are all running without errors, so I guess the code regarding the other forms is ok:
jQuery(function ($) { var $select1 = $('.quform-field-11_150'); $select1.on('change', function () { var value = $select1.val(); if (value=='Online') { $('.quform-field-11_151').val($('.quform-field-11_147').val()); } if (value=='Presenza') { $('.quform-field-11_151').val($('.quform-field-11_154').val()); } }).change(); $('#titolo').text($('.quform-field-8_27').val()); $('#orario').text($('.quform-field-8_19').val()); $('#inizio').text($('.quform-field-8_20').val()); $('#durata').text($('.quform-field-8_21').val()); $('#frequenza').text($('.quform-field-8_22').val()); $('#lezioni').text($('.quform-field-8_23').val()); $('#sede').text($('.quform-field-8_32').val()); $('#costo').text($('.quform-field-8_29').val()); $('#titolo').text($('.quform-field-10_27').val()); $('#orario').text($('.quform-field-10_19').val()); $('#inizio').text($('.quform-field-10_20').val()); $('#durata').text($('.quform-field-10_21').val()); $('#frequenza').text($('.quform-field-10_22').val()); $('#lezioni').text($('.quform-field-10_23').val()); $('#sede').text($('.quform-field-10_32').val()); $('#costo').text($('.quform-field-10_29').val()); $('#worario').text($('.quform-field-10_46').val()); $('#winizio').text($('.quform-field-10_47').val()); $('#wdurata').text($('.quform-field-10_48').val()); $('#wfrequenza').text($('.quform-field-10_49').val()); $('#wlezioni').text($('.quform-field-10_50').val()); $('#wcosto').text($('.quform-field-10_51').val()); $('.quform-field-1_139').val(Math.round($('.quform-field-1_102').val()/20)*10); var calculate = function () { var total = 0; var stotal = 0; var conto = 0; var corso = $('.quform-field-3_57').val(); if (corso) { if ($.inArray('Suono', corso) > -1) { total += parseInt($('.quform-field-3_83').val()); conto+=1; } if ($.inArray('Mixaggio', corso) > -1) { total += parseInt($('.quform-field-3_84').val()); conto+=1; } if ($.inArray('Logic', corso) > -1) { total += parseInt($('.quform-field-3_85').val()); conto+=1; } if ($.inArray('Elettronica1', corso) > -1) { total += parseInt($('.quform-field-3_86').val()); conto+=1; } if ($.inArray('Elettronica2', corso) > -1) { total += parseInt($('.quform-field-3_87').val()); conto+=1; } if ($.inArray('Elettronica3', corso) > -1) { total += parseInt($('.quform-field-3_88').val()); conto+=1; } if ($.inArray('Protools', corso) > -1) { total += parseInt($('.quform-field-3_89').val()); conto+=1; } if ($.inArray('Producer', corso) > -1) { total += parseInt($('.quform-field-3_90').val()); conto+=1; } if ($.inArray('Arrangiamento', corso) > -1) { total += parseInt($('.quform-field-3_91').val()); conto+=1; } if ($.inArray('Tecnico-Live', corso) > -1) { total += parseInt($('.quform-field-3_92').val()); conto+=1; } } if(conto<3) { total=''; $('#form-total').text('Valore corsi selezionati: (Seleziona un minimo di 3 corsi)'); $('#form-stotal').text(''); } else { stotal=Math.round(total/1000*(94.5-(conto*1.95)))*10; $('#form-total').text('Valore corsi selezionati: '+total+'€'); $('#form-stotal').text('Costo finale con sconto: '+stotal+'€'); } $('.quform-field-3_132').val(stotal); $('.quform-field-3_144').val(Math.round(stotal/30)*10); }; // Calculate on page load calculate(); // Recalculate when these select menus are changed $('.quform-field-3_57').change(calculate); });
Labella
ParticipantSolved, the error was in the container!
Labella
ParticipantIt was because of the quotes! I don’t remember where did I copied that code
I will use debug logs from now on, thank you!Labella
ParticipantThank you, but i’m still stuck (sorry..)
I set “Mixaggio” as default parameter for field 1_111, but this doesn’t work:
<?php /* * Plugin Name: Quform Custom Code * Description: Custom code for Quform. * Version: 1.0 */ // Paste in your custom code below add_action('quform_pre_display', function (Quform_Form $form) { $corso = $form->getValueText(‘quform_1_111’); $mysqli = new mysqli("*******", "*******", "*******", "*******"); if ($mysqli->connect_errno) { printf("Connessione al db fallita: %s\n", $mysqli->connect_error); exit(); } $query = "SELECT nome, sessione, anno, prezzo, paypal FROM corsi_new WHERE id_iscrizione='".$corso."'"; $result = $mysqli->query($query); $row = $result->fetch_row(); $form->setValue('quform_1_114', $row[0]); });
whereas this works:
<?php /* * Plugin Name: Quform Custom Code * Description: Custom code for Quform. * Version: 1.0 */ // Paste in your custom code below add_action('quform_pre_display', function (Quform_Form $form) { $corso = $form->getValueText(‘quform_1_111’); $mysqli = new mysqli("*******", "*******", "*******", "*******"); if ($mysqli->connect_errno) { printf("Connessione al db fallita: %s\n", $mysqli->connect_error); exit(); } $query = "SELECT nome, sessione, anno, prezzo, paypal FROM corsi_new WHERE id_iscrizione='Mixaggio'"; $result = $mysqli->query($query); $row = $result->fetch_row(); $form->setValue('quform_1_114', $row[0]); });
Maybe the field 1_111 acquires his default parameter after my $form->getValueText(‘quform_1_111’) request? I don’t understand where is the error. Please help me 🙏
Labella
Participantat the beginning of that code I miss to put the code that causes error: $corso = $form->getValueText(‘quform_1_111’);
Labella
ParticipantGood morning, I’ll try to explain:
I‘m passing a parameter via shortcode to a hidden field
Then I want to use that field value to populate some other hidden fields. To populate those fields I have to pick data from an external database with a sql query, so I was trying to do it with a custom php plugin. This is the code:if ($mysqli->connect_errno) { printf("Connessione al db fallita: %s\n", $mysqli->connect_error); exit(); } $query = "SELECT nome, sessione, anno, prezzo, paypal FROM corsi_new WHERE id_iscrizione='".$corso."'"; $result = $mysqli->query($query); $row = $result->fetch_row(); $corsoid=$row[0]."-".$row[1]."-".$row[2]; add_filter('quform_element_value_Titolo-corso', function ($value) use ($row) { return $row[0]; }); add_filter('quform_element_value_Sessione', function ($value) use ($row) { return $row[1]; }); add_filter('quform_element_value_Anno', function ($value) use ($row) { return $row[2]; }); add_filter('quform_element_value_CorsoID', function ($value) use ($row) { return $corsoid; }); add_filter('quform_element_value_Prezzo', function ($value) use ($row) { return $row[3]; }); add_filter('quform_element_value_Paypal', function ($value) use ($row) { return $row[4]; });
Labella
ParticipantThank you, it works!
- AuthorPosts