get settings of module by page_id – from global module

About this forum
These forums have not been active for several years. They're available for search and reference, but a lot of this information is likely out of date.

For current information, try visiting our Knowledge Base.

Home / Support / Custom Module Development / get settings of module by page_id – from global module

This topic is: not resolved
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #100995

    Sebastian
    Participant

    Hi guys,
    one short question:

    Based on you module “contact-form” we developed a custom module, which sends an request via ajax.

    In the ajax function i have to get the module-settings.

    This code works well:

    $data = FLBuilderModel::get_layout_data(‘published’, $post_id);
    $settings = $data[$node_id]->settings;

    But if the module is saved as “global” the code is not working.

    How can i get the layout_data from the global module?

    Thanks!

    Sebastian

    #101102

    Ben Carlo
    Keymaster

    Hey Sebastian,

    I’ve already assigned another member of the team to assist you with your concern! 🙂

    Ben

    #101500

    Justin Busa
    Keymaster

    Hey Sebastian,

    That’s a bit complicated but we have run into that before with the Subscribe Form module. I’ll try to explain that as best as I can here, but feel free to look at that module’s frontend.js and submit method of the FLSubscribeFormModule class.

    First you’ll need to grab these variables to pass in your ajax request…

    
    this.nodeClass = '.fl-node-' + settings.id;
    this.form = $( this.nodeClass + ' .fl-subscribe-form' );
    
    // These are the vars you need...
    templateId = this.form.data( 'template-id' );
    templateNodeId = this.form.data( 'template-node-id' );
    nodeId = this.form.closest( '.fl-module' ).data( 'node' );
    
    // Send them in your request
    $.post( FLBuilderLayoutConfig.paths.wpAjaxUrl, {
    	action  		: 'your_action',
    	template_id 		: templateId,
    	template_node_id 	: templateNodeId,
    	node_id 			: nodeId
    }, $.proxy( this._submitFormComplete, this ) );
    

    On the server side, you can get the global template data like so…

    $node_id    		= isset( $_POST['node_id'] ) ? sanitize_text_field( $_POST['node_id'] ) : false;
    $template_id    	= isset( $_POST['template_id'] ) ? sanitize_text_field( $_POST['template_id'] ) : false;
    $template_node_id   = isset( $_POST['template_node_id'] ) ? sanitize_text_field( $_POST['template_node_id'] ) : false;
    
    if ( $template_id ) {
    	$post_id  = FLBuilderModel::get_node_template_post_id( $template_id );
    	$data	  = FLBuilderModel::get_layout_data( 'published', $post_id );
    	$settings = $data[ $template_node_id ]->settings;
    }
    else {
    	$module   = FLBuilderModel::get_module( $node_id );
    	$settings = $module->settings;
    }

    Let me know if you have any questions about that.

    Thanks,
    Justin

Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘Custom Module Development’ is closed to new topics and replies.