Jump to content
xisto Community
awesomebill61

Php & Forms Question

Recommended Posts

okay, so i have a form on a php script i am working on, and i want the form to submit to the page it is on...

echo "<form action=\"" . $_SERVER['REQUEST_URI'] . "\" method=\"GET\"> \n";
so say the page it loads on is something like index.php?page=article&id=8
when i submit the form, it ignores the query string and just goes back to index.php
i tried something like
$action = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];echo "<center><br/>\n<form action=\"" . $action . "\" method=\"GET\"> \n";
or
$action = $_SERVER['SCRIPT_NAME'] . "?" . $_SERVER['QUERY_STRING'];echo "<form action=\"" . $action . "\" method=\"GET\"> \n";

is there anyway around this still using a form? if not, i could just list the form options as hyperlinks and pass the variable on through that, or i could just have the website reload to the home page whenever someone updates the theme.

also, a question of curiosity, what is the difference between $_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME']?

Share this post


Link to post
Share on other sites

Check this link out for definitions relating to the final question you asked above.
Both of these are 'Pre-Defined Variables' in PHP.

http://ca.php.net/reserved.variables

Edit the script and echo out the variables in question. That is a standard de-bug technique in most Development Environments. Have the machine tell you what you have done and see if it matches what you 'think' you asked for.

Also, inside the script, have the php_info () called for output. That will list all of the SERVER ARRAY which relate to the script and then you might get a better picutre of the differences in the Server Array contents.

Share this post


Link to post
Share on other sites

Check this link out for definitions relating to the final question you asked above.

Both of these are 'Pre-Defined Variables' in PHP.

 

http://ca.php.net/reserved.variables

 

Edit the script and echo out the variables in question. That is a standard de-bug technique in most Development Environments. Have the machine tell you what you have done and see if it matches what you 'think' you asked for.

 

Also, inside the script, have the php_info () called for output. That will list all of the SERVER ARRAY which relate to the script and then you might get a better picutre of the differences in the Server Array contents.

yea, i had seen that page before, but it didn't really clarify much for me... and calling php_info(), they both return the same value every time.

 

 

 

and also, i answered my own question... i just added this block of code inside my form to re-set all of the values:

foreach($_GET as $key => $value){	echo "<input type=\"hidden\" name=\"$key\" value=\"$value\" />\n";};

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.