lundi 29 février 2016

wp_remote_post for formidable form in a plugin

I have created a WordPress plugin to post a Formidable Form rather than using a url referrer and $_GET.

add_action('frm_after_create_entry', 'PQPCustomFormPosts', 30, 2);

function PQPCustomFormPosts($entry_id, $form_id){
 if($form_id == 8){ //id of the Contact form
    $args = array();
    if(isset($_POST['item_meta'][106])) 
      $args['FirstName'] = $_POST['item_meta'][106];  
    if(isset($_POST['item_meta'][107]))
      $args['LastName'] = $_POST['item_meta'][107]; 
    if(isset($_POST['item_meta'][118])) 
      $args['Company'] = $_POST['item_meta'][118];  
    if(isset($_POST['item_meta'][115])) 
      $args['EmailAddr'] = $_POST['item_meta'][115];  
    if(isset($_POST['item_meta'][119]))
      $args['Subject'] = $_POST['item_meta'][119]; 
    if(isset($_POST['item_meta'][117])) 
     $args['Message'] = $_POST['item_meta'][117];  
    if(isset($_POST['item_meta'][116])) 
      $args['op'] = $_POST['item_meta'][116];  
    $result = wp_remote_post('http://ift.tt/21xSr5N', array('body' => $args));
    print_r($result );
    }
}

This works fine like this with the print_r($result) the php is called after the print_r($result). However if I remove the print_r($result) it doesn't work it stays on the same page. Not sure why that would be.

This is the result of the print_r($result):

Array ( [headers] => Array ( [date] => Tue, 01 Mar 2016 01:31:51 GMT [server] => Apache [vary] => Cookie [link] => ; rel="https://api.w.org/", ; rel=shortlink [connection] => close [content-type] => text/html; charset=UTF-8 ) [body] =>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire