Cannot retrieve field value in PHP custom plugin

Home Forums Quform WordPress Cannot retrieve field value in PHP custom plugin

This topic is: not resolved
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #31806
    Labella
    Participant

    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

    #31812
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #31813
    Labella
    Participant

    Good 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];
    });
     
    #31814
    Labella
    Participant

    at the beginning of that code I miss to put the code that causes error: $corso = $form->getValueText(‘quform_1_111’);

    #31820
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #31827
    Labella
    Participant

    Thank 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 🙏

    #31841
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #31844
    Labella
    Participant

    It 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!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy