开发者

Posting form data to another page and then Posting it again

I am currently using this code to POST a form's data to https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx:

<script type="text/javascript">

        $(document).ready(function(){
            $("#textnextofkin").validate({
                debug: false,
                rules: {
                    name: "required",
                    email: {
                        required: true,
                        email: true
                    }
                },
                messages: {
                    name: "Please let us know who you are.",
                    email: "",
                },
                submitHandler: function(form) {
                    // do other stuff for a valid form
                    $.post('http://www.example.co.uk/erc/process2.php', $("#textnextofkin").serialize(), function(data) {
                        $('#results').html(data);
                    });
                }
            });
        });

</script>

    <form name="textnextofkin" id="textnextofkin" method="POST" action="">
        <div class="hiddenfields">
            <p>Username:<br>
                <input name="EsendexUsername" type="text" value="AAAAA"></p>
            <p>Password:<br>
                <input name="EsendexPassword" type="password" value="AAAAA"></p>
            <p>Account:<br>
                <input name="EsendexAccount" type="text" value="AAAAA"></p>
            <p>Send Name<br>
                <input name="EsendexOriginator" type="text" value="example"></p>
            <p>Recipient:<br>
                <input name="EsendexRecipient" type="text" value="01234123456"></p>
            <p>Message:<br>
                <input name="EsendexBody" rows="3" cols="20" value="Hello test message"></p></div>
                <input type="submit" class="email-buttons" name="submit" value="Text next of kin">
    </form>

process2.php:

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=AAAAA&EsendexPassword=AAAAA&EsendexAccount=AAAAA&EsendexRecipient=01234123456&E开发者_运维知识库sendexBody=test"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);

    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

I need to alter this so that I can POST the form data to process.php instead, and then use process.php to send the information to the Esendex website. I need to do this because process.php contains data I need to include in the form (e.g. $_SESSION['first_name'] ). I suppose I will need to change the Esendex URL above to process.php, but then I don't know what to enter into the process.php page to send the information it recieves.

Could someone please help me to do this?

Thanks for any help


The most important you need to know is that you need curl to be enabled, before you can use the code below. Curl is usually enabled, but its worth checking

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);

    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

EDIT

try this code instead

<?php 
    // Initialise CURL
    $curl_handle = curl_init();
    $data ="EsendexUsername=value&EsendexUsername=value&EsendexAccount=value"; 
    $url = "https://www.esendex.com/secure/messenger/formpost/SendSMS.aspx";
    curl_setopt ($curl_handle, CURLOPT_URL,$url);
    curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($curl_handle, CURLOPT_POSTFIELDS, $data);
    curl_setopt( $curl_handle, CURLOPT_SSL_VERIFYPEER, false );  //so we can post to https  
    $result = curl_exec ($curl_handle);
    curl_close ($curl_handle); 
?>

The above code is just a snippet, so i did not pass all $data as you can see, so you will have to make it more complete. Place the code in process.php and it should send the data to Esendex website.

EDIT I would advise that you read up on CURL to really understand whats going on in the code above. A good starting point would be the php.net site


You post all stuff with ajax to process.php. there you get all variables out of the $_POST array and append your fields.

Then you could use curl to repost to esendex and catch the result, which you then return.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜