Populate dropdown

Home Forums Quform WordPress Populate dropdown

This topic is: resolved
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #29608
    Icemanmx
    Participant

    Hello
    I want to populate dropdown from standalone database, i have this code:

    <?php

    /*
    * Plugin Name: Population of code
    * Description: Special code quform2.
    * Version: 2.0
    */

    // Start Encuesta Post Evento with codes.txt file.

    //quform_error_log($result);

    function mytheme_dynamic_dropdown_values($form)
    {
    $db = new wpdb('xxx', 'xxx', 'xxx', 'localhost');
    $results = $db->get_results("SELECT * FROM code", ARRAY_A);

    $options = array();
    foreach($results as $row) {
    $options[] = array('label' => $row['CODE'], 'value' => $row['CODE']);
    }

    $dropdown = $form->getElement('quform_3_3');
    if ($dropdown instanceof quform_Element_Select) {
    $dropdown->setOptions($options);
    }
    }
    add_action('quform_pre_display_3', 'mytheme_dynamic_dropdown_values');

    ?>

    But it dows not show me nothing, i also changed fron iphorm to quform
    Any help how to do this in Quform2?

    Best Regards
    Icemanmx

    #29623
    Icemanmx
    Participant

    Anyone can help?

    #29629
    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.

    #29631
    Icemanmx
    Participant

    Hello
    I put all in one zip file, screens and debug logs, server log and wp debug log.
    I need to say i have php 7.3 installed…

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #29652
    Icemanmx
    Participant

    Hello
    Someone took a look yet?

    Icemanmx

    #29657
    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.

    #29665
    Icemanmx
    Participant

    Thanks, that worked, and you right i did not type right the column name.

    1000 thanks

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #29667
    Icemanmx
    Participant

    Ok
    One more thing i forgot about..
    Now when i have the code in the database, how can i read it from database and validate that the code excist before sending the form data.

    
    function encuesta_notification_content( PHPMailer $mailer, Quform_Notification $notification, Quform_Form $form ) {
    	ob_start();
    	include __DIR__ . '/encuesta-post-evento.php';
    	$mailer->Body = ob_get_clean();
    }
    add_filter( 'quform_pre_send_notification_1_1', 'encuesta_notification_content', 10, 3 );
    
    add_filter( 'quform_element_valid_1_37', function ( $valid, $value, $element ) {
    
    	//$pathcheck = WP_PLUGIN_DIR . '/surveyhdapg/codes.txt'; // This just checking the path to the wp-plugin folder.
    	//echo '<script language="javascript">';
    	//echo 'alert("Path:' . $pathcheck . '")'; 
    	//echo '</script>';
    
    	$codes = file( WP_PLUGIN_DIR . '/surveyhdapg/codes.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
    
    	if ( !in_array( $value, $codes ) ) {
    		$element->addError( 'Código no válido' );
    		$valid = false;
    	}
    	return $valid;
    }, 10, 3 );
    

    I hope i explained it okay…
    Best Regards
    Icemanmx

    • This reply was modified 4 years, 8 months ago by Icemanmx.
    #29674
    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.

    • This reply was modified 4 years, 8 months ago by Ally.
    • This reply was modified 4 years, 8 months ago by Ally.
    #29677
    Icemanmx
    Participant

    Hello
    I get only This value is not valid.
    I have zipped one file with the codes and the sql so maybe you can help me with it, i really need this…

    I really don´t want to disturb you so much, but i can´t find the problem by my self…

    Best Regards
    Icemanmx

    • This reply was modified 4 years, 8 months ago by Icemanmx.
    Attachments:
    You must be logged in to view attached files.
    #29692
    Icemanmx
    Participant

    Please, anyone can help me to get it right?

    Best Regards
    Icemanmx

    #29699
    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.

    #29705
    Icemanmx
    Participant

    Thanks Ally
    This function perfect, 1000 thanks again for your support.

    Best Regards
    Icemanmx

Viewing 13 posts - 1 through 13 (of 13 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