krv
krv

Reputation: 2920

PHP open another page in iframe POST data

I am creating an Phonegap app that submits user filled data from a form to my url at www.myDomain.com

so the data sent will be using GET so the url possibilities are like this.

www.myDomain.com/processor.php?value1=99
www.myDomain.com/processor.php?value1=ninetyNine

I am opening these sites in an iframe.

Now depending on the value and i can get more than 200 different types of values i want to redirect user to some website posting those values

So i can redirect the above two examples like so

www.numericProcessor.com       //vlaue send by POST is 99
www.alphabeticProcessor.com    //vlaue send by POST is ninetyNine

How do i Go about doing this?

Upvotes: 0

Views: 361

Answers (1)

Xyv
Xyv

Reputation: 739

Sounds like you're searching for a good design decision?

An easy solution could be to use a switch:

<?php
ob_start( );
$value = strip_tags($_GET['value1']);

if (!empty($value )) {
    switch( strtolower($value) ) {
        // add a case for each value you support (in lower case)
        case "99":          $url = "http://www.numericProcessor.com/";     break;
        case "ninetynine":  $url = "http://www.alphabeticProcessor.com/";  break;
        default:            $url = "/InvalidOption.html";                  break;
    }

    header( "location: $url", true, 307 ); // not sure what status you'd prefer
    exit;
}
?>

Might this be a good and easy way to do as you wanted? You can then navigate the iFrame to something like www.myDomain.com/processor.php?value1=99

Please check the code before running, I haven't had the time to test it.

EDIT:

After our chat I think we solved the problem. This untested piece of code might do the trick for you!

<?php  
    $value = strip_tags($_GET['value1']); 

    if (!empty($value )) { 
        switch( strtolower($value) ) { 
            // add a case for each value you support (in lower case) 
            case "99":         $url = "http://www.numericProcessor.com/";    break; 
            case "ninetynine": $url = "http://www.alphabeticProcessor.com/"; break; 
            default:           $url = "/InvalidOption.html"; break; 
        } 

        print " <h1>Please wait while we refer you to the right website</h1>
                <form method='post' action='$url'>
                    <input type='hidden' value='$value' name='<here the name they expact it>'>
                </form>
                <noscript>Please enable JavaScript, else we cannot refer you!</noscript>
                <script language='JavaScript'>
                    document.forms[0].submit();
                </script>";


    }
} 

Make sure to test first, as there are probably some dumb mistakes in it.

Upvotes: 1

Related Questions