The ex-programmer wrote this code: action="?". I couldn't find any PHP script with it. Can anyone tell me what does the form call when submit? I guess it should be the PHP_SELF, but I am not sure.
<form action="?" method="POST" id="pa_form" novalidate="novalidate">
I believe that will cause the browser to send the form request to the current URL, but with an empty querystring.
IE: If you are currently on http://example.com/foo?bar=1 - the target form request will go to the URL "http://example.com/foo?"
I believe it's a self-reference. If it's in the same php script, it just means "self". Typically there are parameters after the question mark (?id=5), however in this case there are none.
Related
I am submitting an HTML form to the same page to handle with PHP and figured out that I can use action="./", which works fine for me so far (in a test environment).
I am a little unsure though because all the examples I find recommend using either
action=""
or
action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
I don't want to use action="" because the HTML Standard specifically states
The action and formaction content attributes, if specified, must have a value that is a valid non-empty URL potentially surrounded by spaces.
Is there any reason not to use action="./"? It seems better (more readable, less PHP) to me but it's confusing me that all the examples I find recommend the PHP approach.
Using ./ works in a lot of cases but can lead to unwanted behaviour if not understood correctly. It's also unnecessary as default behaviour of forms without the action attribute is to submit the form to the same page.
Use <form method="post"> to submit to the same page.
Don't use <form action="" method="post">. This will also submit to the same page but it's invalid according to the HTML standard.
Everything works well behind the scene but my clients see a Page not found after Posting a form.
The form.php must have been found otherwise the data wouldn't be parsed to my e-mail smoothly. I have a redirection page: thankpage.html, which is up and running well when I type its address directly.
what could be going on? any help please?
Anyway,
Instead of calling the Thankpage.html from the form.php, I inserted the following into my "form" element in the contact.html page itself:
onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';"
So it is now:
<form role="form" id="contact-form" method="post" action="form.php" onsubmit="window.location.href='http://www.inglesparticular-sp.com/thankpage.html';">
Somehow it's all working well and I have no "PAGE NOT FOUND" messages!!!
Sorry if I wasn't clear on the question, it's my first one as you can see... cheers!
If we have 2 html files (i.e. one.html and two.html) and within both we have a form which calls the same php file on submit, like:
<form method="post" action="example.php">
, how can example.php know which html file called it?
I'm new to php so any comments are appreciated.
See http://php.net/manual/en/reserved.variables.server.php
The $_SERVER['HTTP_REFERER'] variable, while not trustworthy from a security standpoint, will provide you what you want in most cases.
You could also put a hidden input in your form and pass a variable with the form name or some id that you could use.
There are some ways to solve this problem. It is possible to read the referer from $_SERVER['HTTP_REFERER'].
Or you set a parameter in your form to identify from where you come.
<form method="post" action="example.php?id=xy">
in your example.php you can read the $_GET['id'] and do something with a if statement or a switch.
I have build a form in which you can add images. Unfortunatelly, I am not able to call "move_uploaded_file" in PHP, as the server is running PHP safe mode and there is no way to modify this (I have checked). Therefore, I submit my form to my OWN server, which handles the file uploading.
On my own server, the file however; is not found. I think it has to do with the form calling the external url.
I know this because
echo $_FILES['uploadFile']['name'] ."<br>";
returns just an empty line.
The form itself is:
<form action="http://ejw.patrickh.nl/load.php" method="get" enctype="multipart/form-data" onsubmit ="return checkInput();"> </form>
and contains several input buttons.
Bottomline: the form on my own server submits the file perfectly, however when I make use of the form which is on another site, with the above action; no file is found.
Can this be fixed, and if so; how?
Thanks in advance!
You have to use method="post" to submit files.
Also the enctype attribute alone can be used only, if method="post".
So I have a profile page: profile.php?pin=xx, where I use the GET method for determining which profile to display. I am going to test if $_SESSION['pin'] == $_GET['pin'] and if so, give the option to edit profile.
I don't want to write a-whole-nother script and direct the user to another page. So for usability sake, and keeping the server neat so I'm not always guessing which script does what, I want to mix POST and GET. I've done some research and it seems legal, but how?
<form method="post" action="profile.php?pin=xx">
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
That's all I can think of without really getting the code messy.
If you keep the action attribute empty it will be the same URI including the GET parameters (query-info part of the URI):
<form method="post" action="">
Maybe this is what you're looking for? See HTML <form> tag for a reference about tag and attribute.
If you want to understand how that works: This is a so called Relative URI. It resolves to the Base URI of the document. As the Relative URI is empty, the Base URI is being taken over completely.