Jump to content
xisto Community
nightfox1405241487

Submiting Form Data To "file.php?action=login"

Recommended Posts

I've seen it in some other software but I forget where I saw it and how it was done other than this:In the HTML form:<form action="blah.php" method="post"><input type="hidden" name="action" value="login"><input.......So, would that submit to blah.php?action=login?Thanks,[N]F

Share this post


Link to post
Share on other sites

Well under normal circumstance the code you have would work, but as written the variable 'action' is a POST variable. so to pass the hidden field variable 'action' you would have to change your code to method-'get' like the below.

<?php echo "<form action='blah.php' method='get'><input type='hidden' name='action' value='login'>";echo "<input type='submit'></form>";?>
then use the following to access the variable
blah.php
<?php echo $_GET['action'];?>
Does that help answer your question?
Edited by Houdini (see edit history)

Share this post


Link to post
Share on other sites

Not really... I mean, from what I saw it was actually passing information through the POST method. I mean, I don't want to send sensitive information like passwords through GET. I wish I remember what it was that I saw using it... gosh darn it... grr... what was it called?!?[N]F

Share this post


Link to post
Share on other sites

If you've looked at AJAX it's possibly something you picked up there.

Are you meaning that you want to send the information to blah.php?action=login

Which means your form line would be like

<form action="blah.php?action=login" method="post">

That way you're doing a get request with the action=login, and also posting data along with it to that URL.

Other than this, we'd probably be stumped about what you're talking about.

Cheers,

MC

Share this post


Link to post
Share on other sites

Another example if you didn't understand:

<form action="blah.php" action="POST"><input type="hidden" name="action" value="login"><input type="submit" name="submit" value="Go"></form><?phpif ($_GET['action'] == 'login') {	// some code here....}else {	// some other code here....}?>

When you post something with form and with POST method, it's a good idea to use $_GET['string'] to get string values. Another example:
<form action="login.php" action="POST"><input type="text" name="login"><input type="text" name="pass"><input type="submit" name="submit" value="Login"></form><?phpif ($submit) {  // if form has been submited	if ($_GET['login'] == $adminlogin) && $_GET['pass'] == $adminpass) {		header("Location: adminpanel.php");	}	else {		header("Location: login.php");	}}

Also, if you are posting data to the same page where form is, then you could use <?php $PHP_SELF ?> in "action" instead of "login.php".

I hope this helped you a lot :)

Share this post


Link to post
Share on other sites

Nightfox, I think I know where you're coming from... You want to post both GET and POST data at once. Sounds pointless? Well it's not completely.

I've used that method for pages that use a same PHP script to present all different pages, varying the content based on the GET variables. Sometimes it happens that you want to use a form on such page and sending it all through GET would get you really messy URLs and it could be that the information is delicate. On the otherhand using POST for everything would be inconvenient as user would not get a direct URL to the page and also because you'd might have to rewrite the page generating PHP script.

Oh and it does work, juts put the GET variables in end of the URL in the action argument and use POST as the method.



When you post something with form and with POST method, it's a good idea to use $_GET['string'] to get string values.

What the...

I hope this helped you a lot :P

I'm most certain that it didnt.

Share this post


Link to post
Share on other sites

The action of your form can have a query string if you're using post.I.E.

<form name="SomeForm" action="Action.php?page=maināŒ©=en" method="POST">Login:<input type="text" name="user" value="" />Password:<input type="text" name="pwd" value="" /></form>

I'm not what sure you're trying to do, or what you're actually talking about. But I think that's something similiar. Don't forget that you can change the action of your form at any time with the DOM. document.forms[0].aciton='somaction.php?foo=bar';

Share this post


Link to post
Share on other sites

There are various ways of going about this. One is to change "post" to "get" if you would like to place the variables next to the url. However, if you want to keep it hidden, use post and to retrieve the variables value from the next page you would have to use: <? $_POST[variablename] ?>Of course you replace "variablename" with your variable.

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.