Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Server Request Method

Tags:

forms

php

iframe

I have a form in one file that I submit using method POST. In the file to the form action, I use $_SERVER['REQUEST_METHOD'] === 'POST', but doing a var dump of $_SERVER['REQUEST_METHOD'] shows 'GET'.

Any idea how this could be happening? The form is within an iframe with src = 'targetfile.php?id=30' so the code looks something like this:

<iframe src="targetfile.php?id=30">
    <form method="post" action="targetfile.php" target="credit_results">
        <input type="hidden" name="pid" id="hidden_pid" value="30" />
        <input type="text" class="std_grey" name="first_name_info" id="first_name_info"/>
    </form>
    <iframe name="credit_results" id="credit_results" scrolling="no" frameborder="0" width="960" height="1200"></iframe>
</iframe>
like image 391
The Hawk Avatar asked Nov 13 '22 19:11

The Hawk


1 Answers

Because targetfile.php is getting both GET and POST due to the fact that its posting back to itself and originally loaded with a GET query, I would recommend changing your php to check for specific $_POST variables instead of the REQUEST_METHOD.

For debugging a var_dump( $_POST ); should show things are there.

For actual use

if( !isset( $_POST['varYouNeed'] )) die( 'Missing varYouNeed variable' );
like image 94
Matt R. Wilson Avatar answered Dec 07 '22 23:12

Matt R. Wilson