将Word变量传递到Wordpress上的php文件

时间:2016-08-14 06:29:31

标签: javascript php jquery ajax wordpress

我阅读并尝试了我找到的解决方案,但它对我不起作用。 我有用于预订事件的表单,我将一些数据传递给用于向用户发送短信的php文件,并提供一些信息。

在javascript上我有这段代码:

jQuery( document ).ready( function( $ ) {
    // $() will work as an alias for jQuery() inside of this function

    // old form action is #em-booking
    $(".em-booking-form").attr('action','send-samir.php');
    $(".em-booking-form").submit(function( event ) {
        // show/hide messages.
        $('#messageBeforeSubmit').removeClass('showMessage').addClass('hideMessge');//remove message
        $('#messageAfterSubmit').removeClass('hideMessge').addClass('showMessage');//show message
        $('#orderBeforeSubmit').removeClass('showMessage').addClass('hideMessge');//remove messge


        var get_training = $('#training').text();
        var get_date = $('#date').text();
        var get_time = $('#time').text();
        var get_phone = $('#dbem_phone').val();

        var dataString = 'training='+escape(get_training)+'&date='+escape(get_date)+'&time='+escape(get_time)+'&phone='+escape(get_phone);




        $.ajax({
            type: 'POST',
            url: 'send-samir.php',
            data: {
                'phone': get_phone, 
                'training': get_training, 
                'date': get_date, 
                'time': get_time
            }
        });

    });
});     

我尝试了所有标记为评论的内容,但对我来说都没有用, JavaScript采用我想要的值,我用警报

检查它

在PHP文件中,我有这段代码:

<?php       
    $phone = $_POST['phone'];
    $training = $_POST['training'];
    $date = $_POST['date'];
    $time = $_POST['time'];

    $message .= $training;
    $message .= "\r\n";
    $message .= "\r\n";
    $message .= "date: ";
    $message .= $date;
    $message .= "\r\n";
    $message .= "\r\n";
    $message .= "time: ";
    $message .= $time;
    $message .= "\r\n";
    $message .= "\r\n";
    $message .= "Thank you";
    $message .= "\r\n";

    send_sms($message, $phone); 
    echo "ok";
?>
<?php
    function send_sms($msg, $recepients)
    {
        $msg = str_replace('<', '%26lt;', $msg); // "Cleans" the message from unsafe notes
        $msg = str_replace('>', '%26gt;', $msg); // "Cleans" the message from unsafe notes
        $msg = str_replace('\"', '%26quot;', $msg); // "Cleans" the message from unsafe notes
        $msg = str_replace("\'", '%26apos;', $msg); // "Cleans" the message from unsafe notes
        $msg = str_replace("&", '%26amp;', $msg); // "Cleans" the message from unsafe notes
        $msg = str_replace("\r\n", '%0D%0A', $msg); // "Cleans" the message from enter
        $message_text = $msg;
        $sms_host = "api.inforu.co.il"; // Application server's URL;
        $sms_port = 80; // Application server's PORT;
        $sms_path = "/SendMessageXml.ashx"; // Application server's PATH;
        // EDIT THE FOLLOWING LINES
        $sms_user = "username"; // User Name (Provided by Inforu) ; $sms_user = "USERNAME";
        $sms_password = "password"; // Password (Provided by Inforu) ; $sms_password = "PASSWORD";
        $sms_sender = "my company"; // The SMS sender's (Optional, only English characters, 11 max. ); $sms_sender = "MyCompany";
        $message_text = str_replace (" ", "%20", $message_text); // Encodes spaces into "%20" in the URL;
        $query = 'InforuXML=' . urlencode('<Inforu><User><Username>'.
        $sms_user.'</Username><Password>'.
        $sms_password.'</Password></User><Content Type="sms"><Message>').
        $message_text.urlencode('</Message></Content><Recipients><PhoneNumber>'.
        $recepients.'</PhoneNumber></Recipients><Settings><Sender>'.
        $sms_sender.'</Sender><CustomerParameter>'.
        $customer_parameter.'</CustomerParameter></Settings></Inforu>');
        $fp = fsockopen("$sms_host", $sms_port, $errno, $errstr, 30); // Opens a socket to the Application server
        if (!$fp){ // Verifies that the socket has been opened and sending the message;
            echo "$errstr ($errno)<br />\n";
        } 
        else{
            $out = "GET $sms_path?$query HTTP/1.1\r\n";
            $out .= "Host: $sms_host\r\n";
            $out .= "Connection: Close\r\n\r\n";
            fwrite($fp, $out);
            while (!feof($fp)){
        echo fgets($fp, 128); // Echos the respond from application server (you may replace this line with an "Message has been sent" message);
        }
        fclose($fp);
        }
    }
?>      

我通过向url添加变量来检查代码,例如 send-samir.php?date = date_vale&amp; time =“time_value包含所有变量 它有效。

我似乎无法传递变量,我做错了什么或丢失了什么?

我还在表单代码中添加了action =“send-samir.php”,认为它有所帮助,但它没有帮助。 你还需要形成代码吗?

0 个答案:

没有答案