Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I wonder if anyone can help me with something that's driving me crazy.

I'm trying to implement a series of forms that will write to a CRM and the data must be passed as XML. I'm not particularly experienced at this kind of thing and I'm forced to keep adapting bits of code to make it work.

I've practically written my own plugin as an alternative approach but it won't give me the flexibity I could get from using CF7 or similar. My own version loads the nuSoap library and uses that to send the data (don't ask!) and works fine, albeit with the limitation of a single, hard-coded form.

I don't quite seem to be able to find the code needed to make an action hook work. Can anyone please give me a few pointers?

I'm leaving this project in 2 days and really need to get this working.Example code below. Thanks in advance.

    <?php

    function my_wpcf7_save($wpcf7) {

//declare your variables, for example:
$formtitle = $wpcf7->title;
$firstname = $wpcf7->posted_data['first-name'];
$lastname = $wpcf7->posted_data['last-name'];
$tel = $wpcf7->posted_data['tel'];
$email = $wpcf7->posted_data['email'];
$postal = $wpcf7->posted_data['postal'];

if ( $formtitle == 'Callback Request Form') {

    //write data to Intelegens dbase
    require_once("link-to-nusoap");
    $wsdl="http://webservice.asmx?wsdl";
    $client=new nusoap_client($wsdl,true);

    $xmlInputData='<?xml version="1.0" encoding="utf-8" ?><data><settings><credentials originator="originator" username="user" password="password" /></settings><enquiries><lead productName="Appointment Booking"><customer><name>'.$_REQUEST['firstname'].' '.$_REQUEST['lastname'].'</name><email>'.$_REQUEST['email'].'</email><postcode>'.$_REQUEST['postal'].'</postcode><houseNumber></houseNumber><address></address><city></city><region></region><tel>'.$_REQUEST['phone-number'].'</tel><mobile></mobile><notes></notes></customer></lead></enquiries></data>';

    $param = array('xmlData'=>$xmlInputData); 
    $err = $client->getError();
    if ($err){
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    }

    $params = 'amine';
    $result = $client->call('ImportData', $param);
    $descriptiveResult = "Unknown";

    // Check for a fault
    if ($client->fault){
        $descriptiveResult= print_r($result,true);
    } else { // Check for errors
        $err = $client->getError();
        if ($err){
            $descriptiveResult=$err;
        } else {
            $descriptiveResult=print_r($result,true);
        }
    }

    //fallback email message

             $msg ='<table border="0" style="font: 12px Arial, Helvetica, sans-serif; line-height:20px; " width="350"  align="left" cellpadding="5" cellspacing="1">
                <tr><td colspan="2" align="center"  style="font: 18px Arial, Helvetica, sans-serif; color:#FFFFFF; background-color:#009e5a;">Website Enquiry</td></tr>
                            <tr><td width="35%"  style="font-weight: bold; background-color:#D8DADF; padding-left:10px;" >Name :</td><td style="background-color:#D8DADF; padding-left:10px;" width="65%" >'.$_REQUEST['first-name'].'</td></tr>
                            <tr><td width="35%"  style="font-weight: bold; background-color:#D8DADF; padding-left:10px;" >Last Name :</td><td style="background-color:#D8DADF; padding-left:10px;" width="65%" >'.$_REQUEST['last-name'].'</td></tr>
                            <tr><td width="35%"  style="font-weight: bold; background-color:#D8DADF; padding-left:10px;" >Phone :</td><td style="background-color:#D8DADF; padding-left:10px;" width="65%" >'.$_REQUEST['phone-number'].'</td></tr>
                            <tr><td width="35%"  style="font-weight: bold; background-color:#D8DADF; padding-left:10px;" >Postal Code:</td><td style="background-color:#D8DADF; padding-left:10px;" width="65%" >'.$_REQUEST['postal'].'</td></tr>
                            <tr><td width="35%"  style="font-weight: bold; background-color:#D8DADF; padding-left:10px;" >Email :</td><td style="background-color:#D8DADF; padding-left:10px;" width="65%" >'.$_REQUEST['email'].'</td></tr>



            </table><br/>';

                $subject = 'Appointment Booking';
                $to = "exampleemail";       
                $from = $_REQUEST["email"];

                $headers  = 'MIME-Version: 1.0'."\r\n";
                            $headers .= 'From:'.$from."\r\n";
                            $headers .= 'Reply-To:'.$from."\r\n";
                            $headers .= 'Return-Path:'.$from."\r\n";
                            $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
                            $headers .= 'X-Mailer: PHP/'. phpversion()."\r\n";


                            // $return = "-f$from";
                            // Mail Sent String 
                            $bool=mail($to,$subject,$msg,$headers); 
                            if($bool)
                            {
                                 $messagediv = '<div id="message" class="well">Your enquiry has been sent. One of our operators will contact you shortly</div>';

                            } 
                            else
                                 $messagediv = '<div id="message" class="well">The form contains errors. Please make sure you have completed it correctly to proceed.</div>';
            }

    }
    add_action('wpcf7_before_send_mail', 'my_wpcf7_save',1);
share|improve this question

put on hold as off-topic by Johannes Pille, Pieter Goosen, kaiser yesterday

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

    
So there isn't anyone on here who has knowledge of this kind of thing? –  user2739763 Mar 26 at 16:15