Home Forums Newsletter Developers Unknown error when using the TNP class.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246343
    modiX
    Participant

    Hi,

    I’m trying to integrate this wonderful plugin into Caldera Forms, so that I can combine a contact form with a subscription form, ie. contact me and subscribe to my newsletter right away. For this, I build a new Caldera Forms processor that looks like this:

    `php
    <?php
    /**
    * Plugin Name: The Newsletter Plugin Integration for Caldera Forms
    * Description: Allow customers to subsribe to your newsletter system (The Newsletter Plugin) with Caldera Forms
    * Version: 1.0
    * Author: Martin Braun
    * License: MIT
    * License URI: https://opensource.org/licenses/MIT
    */

    add_filter(‘caldera_forms_get_form_processors’, function($processors)
    {
    $processors[‘tnp_newsletter_subscribtion’] = array(
    ‘name’ => ‘Newsletter Subscribtion’,
    ‘description’ => ‘Subscribe to the newsletter’,
    ‘pre_processor’ => ‘cftnp_newsletter_subscribtion_pre_processor’,
    ‘processor’ => ‘cftnp_newsletter_subscribtion_processor’,
    ‘template’ => __DIR__ . ‘/config.php’
    );
    return $processors;
    }
    );

    function cftnp_newsletter_subscribtion_pre_processor($config, $form, $process_id)
    {
    if($config[‘preprocessor’])
    {
    $email = Caldera_Forms::do_magic_tags($config[’email’]);
    $name = Caldera_Forms::do_magic_tags($config[‘name’]);
    $result = TNP::subscribe([ // this line fails
    ’email’ => $email,
    ‘name’ => $name
    ]);
    if (is_wp_error($result)) {
    return array(
    ‘note’ => $result->get_error_message(),
    ‘type’ => ‘error’
    );
    }
    }
    }

    function cftnp_newsletter_subscribtion_processor($config, $form, $process_id)
    {
    if(!$config[‘preprocessor’])
    {
    $email = Caldera_Forms::do_magic_tags($config[’email’]);
    $name = Caldera_Forms::do_magic_tags($config[‘name’]);
    $result = TNP::subscribe([ // this line fails
    ’email’ => $email,
    ‘name’ => $name
    ]);
    if (is_wp_error($result)) {
    return array(
    ‘note’ => $result->get_error_message(),
    ‘type’ => ‘error’
    );
    }
    }
    }

    /**
    * Setup fields to pass to Caldera_Forms_Processor_UI::config_fields() in config
    *
    * @return array
    */
    function cftnp_newsletter_subscribtion_processor_fields()
    {
    return array(
    array(
    ‘id’ => ‘preprocessor’,
    ‘label’ => ‘Invalidate on fail’,
    ‘type’ => ‘checkbox’,
    ‘required’ => false,
    ‘magic’ => false,
    ‘desc’ => ‘Check this if your form is primarly used to add a newsletter subscribtion. Leave it off if the function in secondary, like on contact forms.’
    ),
    array(
    ‘id’ => ’email’,
    ‘label’ => ‘Email’,
    ‘type’ => ‘text’,
    ‘required’ => true,
    ‘magic’ => true
    ),
    array(
    ‘id’ => ‘name’,
    ‘label’ => ‘Name’,
    ‘type’ => ‘text’,
    ‘required’ => true,
    ‘magic’ => true
    ),
    );
    }
    `

    Without the following code it works, so something is wrong with this call:

    `php
    $result = TNP::subscribe([ // this line fails
    ’email’ => $email,
    ‘name’ => $name
    ]);
    `

    Unfortunately, I don’t know how I can catch the error, since the whole thing runs from an AJAX call and returns nothing but a 500. WP_DEBUG / WP_DEBUG_LOG doesn’t work.

    Do you know what’s wrong on my call? Thank you!

    #246353
    Stefano
    Keymaster

    Errors of type 500 are stored in the server error logs. If you can access it there should be a clear explanation of the error so we can understand how to solve!

    Stefano.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.