Variable should decide if method is POST or GET


#1

telling my form if method is POST or GET, which depends on a variable


Hi all,

does anyone know a way to tell a form’s method to be GET or POST which is up to a variable. the error output should start below all textfields.
i have a hidden field ‘$_REQUEST[‘sendForm’]’ which is’s default value is ‘0’.
when you hit the submit button (image submit button), all fields will be checked. if ererything’s ok, $_REQUEST[‘sendForm’]’ is set to ‘1’ and it should decides what action to take: GET or POST …

also tried the header(‘location…php’) stuff with a function at the beginning of the script. everytime i call my function from below (after checking my fields) it tells me that the headers already sent…

here is the code:

<?PHP if($_REQUEST['sendForm'] == 1) // decide grrr..grrr { $handling = "GET"; $loc = "d_submitResponse.php"; print ""; } else { $handling = "POST"; $loc = "$_SERVER[PHP_SELF]"; } print ""; ?> <? foreach($_REQUEST as $key => $value) { $countFields = count($_REQUEST); // how many textfields if(!empty($value)) { $setFields++; } if($countFields == $setFields && $_REQUEST['PASS'] == $_REQUEST['PASS-CONFIRM']) { $formOK = 1; } if(!empty($_REQUEST['PASS']) == !empty($_REQUEST['PASS-CONFIRM']) && !empty($_REQUEST) && $formOK == 1) { $_REQUEST['sendForm'] == 1; } } ?>

#2

I suspect that the only way to really do this is with Javascript. For PHP to do this you would actually have to SUBMIT a page so that PHP knows whether the (next) page is to be POST or GET.

You could conceivably change the GET or POST method with javascript before the actual submit.


#3

Hi,

Like this

…some php-code

if(!empty($_REQUEST[‘PASS’]) == !empty($_REQUEST[‘PASS-CONFIRM’]) && !empty($_REQUEST))
{
$_REQUEST[‘sendForm’] = 2;
}

i tried this and it also not works. $_REQUEST[‘sendForm’] stays ‘1’
.did i forget something ?

Olli