Page 1 of 1

getting url query and make it as an action in a form

Posted: Tue Jul 14, 2009 3:07 pm
by xiaomahe
hi everyone,

how to make a form do an action on the same page but with url query?

for example: my url is : https://xx/xx/view.php?num=2

and i would like my form to be like

Code: Select all

<form name="checkcode" action="same as the url above">
and remember, the url above is dynamic, as it always change depend on what user has click, so it can be 2,3 or 4

So, how do i make the action to be dynamic as well.?

Re: getting url query and make it as an action in a form

Posted: Tue Jul 14, 2009 3:28 pm
by requinix

Code: Select all

$url = "https://xx/xx/view.php?num=" . (int)$_GET["num"];

Code: Select all

<form name="checkcode" action="<?=$url?>">

Re: getting url query and make it as an action in a form

Posted: Tue Jul 14, 2009 4:02 pm
by xiaomahe
hai thnks for replying.. i oso found an alternative way to solve this

Code: Select all

//Function to get the URL query so that it can display the corresponding message
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    }

Code: Select all

<form action="<?php echo $editFormAction; ?>" method="POST">
but yours is simpler. Thanks!!