-1

So basically, if they type in a zip code between 85700 and 85775 I want it to post to: http://medicarechoicesofarizona.com/

If anything else is entered, I want it to post to http://www.ehealthmedicare.com like it does below. I guess JavaScript would be fine too but PHP would be great because this is for a Wordpress widget. Thanks everyone!

<form action="http://www.ehealthmedicare.com/find-coverage?allid=Med35993" method="post" target="blank" _lpchecked="1">
    <p style="font-size:16px; text-align:center">
        Zip Code:  <input type="text" name="zip" style="width:60px; height: 25px;">
    </p>
    <p style="text-align:center">
        <input type="image" src="/wp-content/plugins/medicare-quote-widget/ehealth-medicare-go.png" title="Find Medicare Insurance Options" alt="Find Medicare Insurance Options" class="go-btn">
    </p>
</form>
4

2 回答 2

1

您可以为此使用 curl 扩展。检查功能例如:

function post($url, $data) {
    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, 1);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $data);

    //execute post
    $result = curl_exec($ch);

    //close connection
    curl_close($ch);
}

像这样称呼它:

if($zip > 85699 && $zip < 85776) {
    $url = 'http://url1';
} else {
    $url = 'http://url2';
}

post($url, 'foo=bar&hello=world');
于 2013-05-02T23:29:15.987 回答
0

实际上,这可以用纯 PHP 来完成:

<form action="forwarder.php" method="post" target="blank" _lpchecked="1">
    <p style="font-size:16px; text-align:center">
        Zip Code:  <input type="text" name="zip" style="width:60px; height: 25px;">
    </p>
    <p style="text-align:center">
        <input type="image" src="/wp-content/plugins/medicare-quote-widget/ehealth-medicare-go.png" title="Find Medicare Insurance Options" alt="Find Medicare Insurance Options" class="go-btn">
    </p>
</form>

然后将其添加到forwarder.php

<?php
    if($_POST)
    {
        $zip = (int)$_POST['zip'];
        if($zip >= 85700 && $zip <= 85775)
        {
            header('Location: http://medicarechoicesofarizona.com/');
        }
        else
        {
            header('Location: http://www.ehealthmedicare.com/find-coverage?allid=Med35993');
        }
    }
?>
于 2013-05-02T23:47:15.330 回答