Jump to content

Recommended Posts

Hello Everyone,

 

in my index.php page I have a basic switch statement which is used with $_GET['page'] so I can display different pages within index.php. Which makes the URL look like this(no matter what page I am on):

/index.php?page=mash

 

Now, my problem is, I am trying to send a GET in a form in mash.php(the URL above). But what is happening is, the submitted GET is replacing the page GET, so my URL looks like this once the submit button is clicked:

/index.php?health_needed=35

 

And when this happens there is 2 problems:

 

1. The home page is loaded instead of mash.php which is in the form.

2. nothing can be done with the submitted data as it isn't submitted to mash.php

 

So how do I submit the GET to mash.php without screwing up the URL?

 

I believe its gotta be something along the lines of

/index.php?page=mash&health_needed=35
But i'm not completely sure.

 

here is my form incase it helps:

<?php //$health_needed = 35; in my example  ?>
<form name="mash_treatment" method="get" action="index.php?page=mash&">
		<input type="hidden" name="health_needed" value="<?=$health_needed?>">
		<input type="submit" value="Receive Treatment">
</form>

 

Regards ACE

I am...

 

here's the rest of the code:

<?php 
$health_needed = $player_maxhealth - $player_currenthealth;

if(!isset($_GET["health_needed"])) {

if($player_currenthealth < $player_maxhealth) 
{ 
echo "You have been wounded in battle, if you would like to receive medical treatment you can receive it now for <b>$500</b>.";


?>

<br><br>

<form name="mash_treatment" method="get" action="index.php?page=mash&">
		<input type="hidden" name="health_needed" value="<?=$health_needed?>">
		<input type="submit" value="Receive Treatment">
</form>

<?php 
}
} elseif(isset($_GET["health_needed"]) && $player_currenthealth < $player_maxhealth) {

$health_you_need = $_GET["health_needed"];

  mysql_query("UPDATE `cf_users` SET `currenthealth` = currenthealth+$health_you_need WHERE `id`='" . $player_accountid . "' LIMIT 1") or die('Query:<br /> Updating your Current Health in M*A*S*H <br /><br />Error:<br />' . mysql_error());

  mysql_query("UPDATE `cf_users` SET `money` = money-500 WHERE `id`='" . $player_accountid . "' LIMIT 1") or die('Query:<br /> Updating your money in M*A*S*H <br /><br />Error:<br />' . mysql_error());

echo "You are now back to full health!";  

unset($_GET["health_needed"]);

} 

if($player_currenthealth == $player_maxhealth) {

echo "You do not require medical treatment.";

}

?>

This is the perfect way. - /index.php?page=mash&health_needed=35.

 

 

 

If you want the url like this /index.php?health_needed=35 then you need to pass value of page in hidden variable.

<form>

  <input type="hidden" name="page" value="mash">

</form>

 

And need to use REQUEST['page'] inseted of $_GET['page'].

This is the perfect way. - /index.php?page=mash&health_needed=35.

 

 

 

If you want the url like this /index.php?health_needed=35 then you need to pass value of page in hidden variable.

<form>

  <input type="hidden" name="page" value="mash">

</form>

 

And need to use REQUEST['page'] inseted of $_GET['page'].

 

Very far from perfect

First your form  has no action and no way to submit it so I don't see a use to it.

Secondly you dont' define a process type (GET/POST) for it

Thirdly $_REQUEST is a bloated superglobal that could be injected

so for a not perfect solution use what they posted

The default action in a form is to send the information back to the page the form is on. The default method is "GET".

 

Ken

 

Defaults, but is that acid2 way of doing it?

 

When all browsers go acid2 in fifty years will that still work?

The default action in a form is to send the information back to the page the form is on. The default method is "GET".

 

Ken

 

Defaults, but is that acid2 way of doing it?

 

When all browsers go acid2 in fifty years will that still work?

The acid2 test has nothing to do with how forms are submitted. The acid2 test is just a benchmark for how well browsers support standards.

Acid2 is a standard put forth that all browsers are suppose to achieve at some point for rendering xhtml/html.  The default way to handle a form would be part of the Acid2 criteria as it falls under the scope of xhtml/html rendering.

Also I believe w3 compliance to transitional or strict doc types fail when a form lacks a method or action.

Bleh....

 

When ever you submit a form using GET, IE and FF (and probably others) use the base url put into the action tag, not any additional information with it.

 

Also if <input type="text" name="name" value="corbin" /> would make ?name=corbin (if not changed), then why wouldn't <input type="hidden" name="page" value="somepage" /> make ?page=somepage ?

 

I use get forms for a lot of things, and I have to do that all the time.

 

So my next question....  If it all goes into the url, why would you need to use $_REQUEST instead of the better $_GET?

 

Anyway, hope I helped, and yes, sorry for basically repeating everything others said.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.