wordpress plugin mailjet-for-wordpress can not insert contact properties field to newsletter form in frontend

I use plugin mailjet-for-wordpress.

What I want

Read More

want user to input thier nom,prenom and email in front end like this :http://gyazo.com/b58675c671584f8edc6ab6d703370ba9

My problem

for field I just add like nom,prenom it does not show in my admin page the same as email field when user subcribe : http://gyazo.com/9b72fdc03d22732cf21ddac9f70b2c33

what i have tried

I have tried to create contact properties field in mailjet like nom,prenom. And I’m also try to modify widget “Subscript to our newsletter” I add more fields in the newsletter form. I have modify code as below :

file mailjet-widget.php

    // WIDGET CODE GOES HERE
    echo '
    <form class="subscribe-form">
        //add field nom
        <input type="text" name="nom" placeholder="' . __('Nom', 'wp-mailjet') . '" class="username">

        //add field prenom
        <input type="text" name="prenom" placeholder="' . __('Prenom', 'wp-mailjet') . '" class="username">
        //email it is original field in default newsletter mailjet form
        <input id="email" name="email" value="" type="email" placeholder="' . __('your@email.com', 'wp-mailjet') . '" />

        <input name="action" type="hidden" value="mailjet_subscribe_ajax_hook" />
        <input name="list_id" type="hidden" value="' . $list_id . '" />
        <input name="submit" type="submit" class="mailjet-subscribe" value="' . __($button_text) . '">
    </form>
    <div class="response">
    </div>';

And also in this function mailjet_subscribe_from_widget()

public function mailjet_subscribe_from_widget()
{
    // Get some variables - email, list_id, etc.
    $email = $_POST['email'];
    $list_id = $_POST['list_id'];
    //field add
    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];

    // Add the contact to the contact list
    $result = $this->api->addContact(array(
        'Email'     => $email,
        'Nom'       => $nom,
        'Prenom'    => $prenom,
        'ListID'    => $list_id
    ));

    // Check what is the response and display proper message
    if(isset($result->Status)) {
        if($result->Status == 'DUPLICATE'){
            echo '<p class="error">';
            echo sprintf(__("The contact %s is already subscribed", 'wp-mailjet'), $email);
            echo '</p>';
            die();
        }
        else if($result->Status == 'ERROR'){
            echo '<p class="error">';
            echo sprintf(__("Sorry %s we couldn't subscribe at this time", 'wp-mailjet'), $email);
            echo '</p>';
            die();
        }           
    }

    // Adding was successful
    echo '<p class="success">';
    echo sprintf(__("Thanks for subscribing with %s", 'wp-mailjet'), $email);
    echo '</p>';
    die();
}

I have tried to search and test like this for a few days but still can not get the result.I am new with the plugin mailjet-for-wordpress plugin,
Do anyone know help me to find the solution please,

Thanks in advanced,

Related posts

1 comment

  1. We would like to suggest 2 additional API calls.

    1. Get the contact ID
      GET https://api.mailjet.com/v3/REST/contact/user@email.com
      You should receive a response similar to
        "Count": 1,
        "Data": [ {
            "CreatedAt": "2014-12-03T12:30:10Z",
            "DeliveredCount": 79,
            "Email": "user@email.com",
            "ID": 5,
            "IsOptInPending": false,
            "IsSpamComplaining": false,
            "LastActivityAt": "2015-04-07T08:35:51Z",
            "LastUpdateAt": "2014-12-03T12:30:10Z",
            "Name": "",
            "UnsubscribedAt": "",
            "UnsubscribedBy": "" 
        }],
        "Total": 1
    
    1. Then by using the id from the previous call, you should update contacts properties (in this case id=5)

    PUT https://api.mailjet.com/v3/REST/contactdata/5

            {
        "Data": [ {
        "Name": "nom",
        "Value": "Bond" 
        }, {
        "Name": "prenom",
        "Value": "James Bond" 
        }
    

    The response will contain the same Data object with updated data.

    To integrate those two API requests in WP plugin, you should add and create more PHP methods.

    Example for the first API call:

    In mailjet-api-strategy.php
    in class WP_Mailjet_Api add
    public function     findContactByEmail($email) 
    
        {
          return $this->context->findContactByEmail($params);
        }
    
    (assuming you are v3 user) in class WP_Mailjet_Api_Strategy_V3 add
    public function findContactByEmail($email) 
    
            {
          return $this->{'contact/'.$email}(array(
            'method' => 'GET',
          ))
        }
    

    In mailjet_subscribe_widget() get the contact id with

     $result = $this->api->findContactByEmail(array(
    'Email' => $email,
    

    The ID here would be in $result-Data[0]>ID

    For the second call, please use the example to integrate it.

Comments are closed.