In PHP, how do I specify different form actions depending on input text?

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>

Answers


Actually, this can be done with pure 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>

and then add this to 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');
        }
    }
?>

You can use the curl extension for that. Check function for example:

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);
}

Call it like this:

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

post($url, 'foo=bar&hello=world');

Need Your Help

AngularJS Bootstrap alert dismiss-on-timeout attribute doesn't work

angularjs twitter-bootstrap timeout alert angular-ui-bootstrap

I'm trying to use AngularJS Bootstrap alerts like explained here with the "dismiss-on-timeout" attribute. It has no effect in this example, the alert just appears regularly and doesn't disappear.

XCode: Duplicate Symbol

xcode private-methods duplicate-symbol

I have a C function heightParameter that is a simple tool that I use in a couple of my UIViewControllers. I am declaring this only in my main implementation of each UIViewController subclass (in th...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.