Results 1 to 9 of 9
  1. #1

    $PHP_SELF in HTML form?

    Hi,

    I have an HTML form and i want to pass the current URL through on it called url.

    Here is the code I am using:

    <input type="hidden" name="url" value="<? echo $_SERVER['PHP_SELF']; ?>"/>

    This works fine, but it does not also carry the GET variables... so if I'm on a page like index.php?page=news&id=42 ... the only thing that stays is "index.php"

    I have also tried

    <input type="hidden" name="url" value="<? echo $PHP_SELF; ?>"/>

    ...same thing.

    Any help would be appreciated. Thanks.
    Executive Director, KnicksCity.com

  2. #2
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342

    Re: $PHP_SELF in HTML form?

    PHP_SELF just echos the page name... not the GET/POST variables...

    do it manually... or if you do not know what will be in the GET, do a fuctuion of which to extract GET and add it to the variable..

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  3. #3
    Any ideas for the function? I'm still pretty new when it comes to PHP.
    Executive Director, KnicksCity.com

  4. #4
    Join Date
    Mar 2004
    Location
    USA
    Posts
    4,342
    I know there are other easy ways to solve it... but I dont know..

    I always take the hard way (maybe somone can come and advise).


    PHP Code:

    foreach($_GET as as $option => $value){
         if(
    $add_to_link != NULL){
         
    $add_to_link .= "&$option=$value";
         } else {
         
    $add_to_link "?$option=$value";
         }

    and just add it to link: <?php echo $_SERVER[PHP_SELF].$add_to_link;?>

    Peace,
    Testing 1.. Testing 1..2.. Testing 1..2..3...

  5. #5
    I think azizny submitted the right answer

  6. #6
    Exactly what I'm looking for. Thanks for your help


    except, typo: one extra "as" in the first line.
    Executive Director, KnicksCity.com

  7. #7
    Join Date
    Dec 2003
    Location
    ./Southest Missouri
    Posts
    601
    Are there any drawbacks to just leaving it blank? I would think action="" would work just fine.

  8. #8
    Well, it's passing to another script that uses this url value
    Executive Director, KnicksCity.com

  9. #9
    Join Date
    Dec 2003
    Location
    ./Southest Missouri
    Posts
    601
    ah, gotcha, I thought you were just reloading the same page.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •