• Resolved tgilber007

    (@tgilber007)


    Hi, I try to create a poll via API after submitting the specific form.
    The issue is poll form name, poll answers created successfully, but in the settings (poll question, result behavior, result style) not created.

    https://prnt.sc/m-DnXhjLjrbw

    
    add_action('forminator_form_after_handle_submit','generation_form', 10, 2 );
    
    function generation_form($form_id, $response) {
    	if ($response['success']){
    		if ($form_id == 60){	
        $answers = array(
    	array(
    		"title" => "Tester 1",
    		"element_id" => "answer-1"
    	),
    	array(
    		"title" => "Tester 2",
    		"element_id" => "answer-2",
    		"use_extra" => 1,
    		"extra" => "Tester"
    	),
    );
    
    $settings = array(
    	"poll-question" => "Test?",
    	"results-behav" => "show_after",
    	"results-style" => "bar",
    	"enable-ajax" => "true",
    );
    
    $id = Forminator_API::add_poll( "Does it work?", $answers, $settings );
             }
    	}
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @tgilber007

    I hope you’re well today!

    The code that you are using seems to be almost literally copied from our API docs (except that you wrapped it up in callback function for action hook, which is fine, I believe).

    Yet, I tested it and got the very same results as you do. I think something might have changed in code on our end but I need to consult it with our Forminator developers so I’ve asked them about it and am waiting for their feedback.

    I’d appreciate some patience as they need to check it. We’ll update you here soon with more information on the issue.

    Best regards,
    Adam

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @tgilber007

    I just got feedback from our developers and it seems that there’s a bug on our end. I’m sorry about it.

    We’ll be fixing it with one of future releases but as an immediate patch you can use a slightly different code to create polls. Here’s the version that will work fine:

    add_action('forminator_form_after_handle_submit','generation_form', 10, 2 );
    
    function generation_form($form_id, $response) {
    	if ($response['success']){
    		if ($form_id == 60){	
    			$answers = array(
    				array(
    					"title" => "Tester 1",
    					"element_id" => "answer-1"
    				),
    				array(
    					"title" => "Tester 2",
    					"element_id" => "answer-2",
    					"use_extra" => 1,
    					"extra" => "Tester"
    				),
    			);
    
    			$settings = array(
    				"poll-question" => "Test?",
    				"results-behav" => "show_after",
    				"results-style" => "bar",
    				"enable-ajax" => "true",
    			);
    
    			$id = Forminator_API::add_poll( "Does it work?", $answers, $settings );
    			if( !is_wp_error( $id ) ){
    				$form_meta = get_post_meta($id, 'forminator_form_meta', true);
    				if( $form_meta ){
    					if( isset( $form_meta['settings'] ) ){
    						$form_meta['settings']['poll-question'] = $settings['poll-question'];
    						$form_meta['settings']['results-behav'] = $settings['results-behav'];
    						$form_meta['settings']['enable-ajax'] = $settings['enable-ajax'];
    						$form_meta['settings']['results-style'] = $settings['results-style'];
    						update_post_meta($id, 'forminator_form_meta', $form_meta);
    					}
    				}
    			}
            }
    	}
    }

    Best regards,
    Adam

    Thread Starter tgilber007

    (@tgilber007)

    1) Hi, I try to delete a poll via API after calling a function it returns – wordpress error (There has been a critical error on this website.)

    function delete_poll() { 
    $poll_id = 65;
    $form = Forminator_API::delete_poll( $poll_id );
    }
    

    Or

    2) How to delete the poll automatically after the vote open until time (specified time)
    https://prnt.sc/qPaizhlkRtl7

    • This reply was modified 2 years, 5 months ago by tgilber007.
    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @tgilber007

    1) Hi, I try to delete a poll via API after calling a function it returns – wordpress error (There has been a critical error on this website.)

    Can you let us know how you are calling this function? On any specific hook?

    Also, kindly enable the debug mode https://wpmudev.com/blog/debugging-wordpress-how-to-use-wp_debug/ and let us know the fatal error line.

    I could notice some weird behaviour in this method returning:

    Uncaught Error: Class 'Forminator_Admin_Module_Edit_Page' not found

    And I would like to know if this is the same log for you.

    2) How to delete the poll automatically after the vote open until time (specified time)

    The easiest way is by creating a custom cronjob event to run on a specific time https://www.elegantthemes.com/blog/tips-tricks/how-to-add-cron-jobs-to-wordpress

    Best Regards
    Patrick Freitas

    Thread Starter tgilber007

    (@tgilber007)

    1. resolved
    2. Where to see the list of available actions and filters for forminator plugin. Like this https://hookr.io/plugins/buddypress/2.8.2/actions/

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @tgilber007,

    We do not have the list of available actions and filters documented as of now. Can you please check if Formiantor API helps instead: https://wpmudev.com/docs/api-plugin-development/forminator-api-docs/

    Kind Regards,
    Nebu John

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘New Poll Via API’ is closed to new replies.