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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xiaomahe
Forum Newbie
Posts: 11
Joined: Sun Jun 28, 2009 10:14 am

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

Post 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.?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

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

Post by requinix »

Code: Select all

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

Code: Select all

<form name="checkcode" action="<?=$url?>">
xiaomahe
Forum Newbie
Posts: 11
Joined: Sun Jun 28, 2009 10:14 am

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

Post 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!!
Post Reply