D
D
DrunkMaster2015-12-07 23:57:21
PHP
DrunkMaster, 2015-12-07 23:57:21

How to submit a form to the same page?

If you need to process the form on the same page, you can do this:
<form action="" method="POST">
But I saw examples where some global variable is put into action = "", I don’t remember exactly, from $ _SERVER like.
Why, what's the point, what's the right way?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Pavlenko, 2015-12-08
@Akdmeh

$_SERVER['PHP_SELF'] is written. But I can't say that this is the best solution. But at your stage it should be enough.
The point is that an empty action is not valid. And different browsers may have different behavior. Someone will translate to the same page, and someone - to the index ...
Therefore, it is better to avoid such ambiguities

A
Anar4you, 2015-12-08
@Anar4you

Put a link to the same document, and in the code check if the button is pressed if{ isset $post submit (I'm writing from the phone so something like this)} else{ showing the form}

S
sivabur, 2015-12-09
@sivabur

So do not write the action attribute and it will by default throw on the same page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question