Is ther a posibility to send variables back to same page....

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
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Is ther a posibility to send variables back to same page....

Post by Skywalker »

Is ther a posibility to send variables back to same page. With php_self?

I have a form, that has a send button (hehe) but the inserted values have to be send to the same page back again. it works like some kind of refresh.


doe I have to do it like this then or do I have to use php_self?

<form method="post" action="php_self">?
or
<form method="post" action="the name of this page.php">?

witch one is beter to use?

Thenk for you help, Skywalker
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You can use either $_SERVER['PHP_SELF'] or the page's actual name as the action in the form. Using $_SERVER['PHP_SELF'] means that if you change the name of the file you don't have to worry about editing the HTML.

Mac
User avatar
Heavy
Forum Contributor
Posts: 478
Joined: Sun Sep 22, 2002 7:36 am
Location: Viksjöfors, Hälsingland, Sweden
Contact:

Re: Is ther a posibility to send variables back to same page

Post by Heavy »

Skywalker wrote:

Code: Select all

<form method="post" action="php_self">
Most people understand, but for other newbies, like me, let's correct the above:

Code: Select all

<form method="post" action="<?=$_SERVER&#1111;'PHP_SELF']?>">
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Don't forget that not everybody has short tags (<? ?>) enabled so for newbies it's good to point out:

Code: Select all

&lt;form method="post" action="&lt;?php echo $_SERVER&#1111;'PHP_SELF']; ?&gt;"&gt;
too.

Mac
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

most browsers (all I got to know until now) will send back the data to the same url if the action-property is missing, e.g.

Code: Select all

<form method="POST">
	<input type="submit" name="submit" value="true" />
</form>
It works but does not comply to any :?: standard and http://validator.w3.org/check will not approve the document ;)
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

Ok thenk you people :D
Post Reply