Home › Forums › Quform WordPress › Cannot retrieve field value in PHP custom plugin
- This topic has 7 replies, 2 voices, and was last updated 4 years, 3 months ago by Labella.
- AuthorPosts
- August 25, 2020 at 2:36 am #31806LabellaParticipant
Hi, I’m trying to use a field value inside a custom plugin, following your examples
This is my code:
$corso = $form->getValueText(‘quform_1_111’);Where am I wrong? Frontend and backend crashes when I put that code in the plugin, they talk about “critical error” and I have to delete that row from the plugin, and clear the cache of my browser
Matteo
August 25, 2020 at 10:59 am #31812AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 25, 2020 at 12:10 pm #31813LabellaParticipantGood 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]; });
August 25, 2020 at 12:33 pm #31814LabellaParticipantat the beginning of that code I miss to put the code that causes error: $corso = $form->getValueText(‘quform_1_111’);
August 26, 2020 at 10:56 am #31820AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 27, 2020 at 1:12 am #31827LabellaParticipantThank 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 🙏
August 27, 2020 at 12:03 pm #31841AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
August 27, 2020 at 6:30 pm #31844LabellaParticipantIt 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! - AuthorPosts
- You must be logged in to reply to this topic.