HTTP POST issue without filename - php

I have a form that uses the POST method to send data. The POST destination is configured as "http://www.example.com/form". However, the actual POST file is "http://www.example.com/form/index.php".
Because the action does not include the file name (index.php), the POST variables are not making it to the page. (This said, GET requests seem to work fine.)
Short of changing the action and/or method, is there any fix for this? Can I implement a mod_rewrite rule to pass the POST values along to the page?

I could not reproduce this with
<form action="/test/" method="POST">
But I was able to reproduce it with
<form action="/test" method="POST">
In the second case my Apache send as Moved-Permanently redirect to /test/ and the POST variables are lost.
This redirect is done by mod_dir.
If you disable mod_dir links to a directory without a trailing slash a simply not working any more.
The only advice I can give you is to fix the form's action.

Related

Keeping $_POST data after submit while getting rid of index.php in redirected URL

Within a Joomla template, I'm trying to use a form (within a Joomla article to keep the template's layout) and pass the data to a processing php-file (for example to enter this data in a mysql db). No Java.
When I hit submit, I'm losing all POST information before it reaches this processing PHP file. I believe this is because Joomla has index.php entered within any URLs.
I understood that any redirects (eg. htaccess changes), clears my needed POST variables.
How can I click on submit-button, keep the POST variables and send these to the processing PHP-file?
Thanks for any help..!
I tried changing the Joomla based URL Rewriting option, but this messes up all my other URLS.
I tried the webhost redirecting tool - this works but kills all data
I tried htaccess changes, but this doesn't seem to have any effect..plus this would also kill the POST variables
I tried relative pathing, doesn't work because of the index.php mixing in anyway.
In my form-file (the actual Joomla article in the template)
´´´´
<form action="process.php" method="POST" />
<input type="submit" value="Submit" />
</ form>
´´´´
The form.php file is located in the same folder as the process.php folder.
The form-php contents' URL has also the index.php, but is functional.
In the processing code I have this:
´´´´´´´´´´
$table = $_POST['formID'];
echo ($table);
$keys = implode(", ", (array_keys($_POST)));
$values = implode("', '", (array_values($_POST)));
´´´´´´´´´´
but the $table is simply empty, due to this index.php part I can't get rid of, I believe.
All this code is in a remote folder following the classical joomla folder structure for modules, so /modules/mod_xyz/tmpl/process.php
Is there a way to properly target the form action so that the index.php is not getting mixed in in any files in the above-mentioned folder? I'd like to keep the index.php in all other links, as they work, and also, I'd like to understand why this isn't working?
Thanks a lot again
Idea is just to be able to click on the submit on the form, so that it POST data can be used in the process.php file (=entering data in the mysql database).
This question can be considered closed.

Different between actions

I want to know different between <form action="#" method="post"> and <form action="name of file" method="post">
I am always using # but don't know disadvantages.
Can you explain why I should use # or file name?
Thanks
form action = file name
It is used to send a request on the other page(i.e your file name) containing your form fields(inputs) with methods like GET and POST.
example my HTML page is having a form then and my PHP page is having all the backend code. Whatever I need to do with form inputs. I will give the file name of my PHP page in action. the action attribute of the form is used to send the form request to the destination we want to with methods like the POST and GET. If you do not want to send a request to another Page and want it to your default page. You can leave action ='' attribute of the form empty as I did.
An action of # indicates that the form stays on the same page, simply suffixing the URL with a #. A similar use occurs in anchors. Link for example, will stay on the same page.
Thus, the form is submitted to the same page, which then processes the data etc
The content of action allows you to know where you will put the code that will process the request.
If you put the name of a file it, then his file will process the request.
For example: you have your form on the index.php page and you want to put the PHP code of the form in a process.php file. You will put process.php in action (action="process.php").
If you do not put anything it is like sending the content of the request to the same file (index.php).

Calling a php page from an html-form action, but causing a "404 Not Found" error

I have created an HTML form which calls a php page (function) when submitted:
<form name="business" action="create-account-and-profile.php" method="POST">
<table>
<tbody>
....
I have made sure that create-account-and-profile.php is in the same directory. The php file is a form data processor which starts as follows:
require_once (ABSPATH . "wp-admin/includes/user.php");
if (isset($_POST['personal_email_id'])) {
$email_id = $_POST['personal_email_id'];
.......
For some reason unknown to me, when the form is submitted, a “404 not found” error was generated.
This is on a WORDPRESS platform, hosted in the Openshift environment.
I searched and reviewed relevant posts on this and WORDPRESS forums.
Any advice will be greatly appreciated.
JZ
You must check that create-account-and-profile.php is in the same relative path of HTML page containing the form. e.g.:
if you form is in
example.com/subdir/form.html
the php file must be in
example.com/subdir/create-account-and-profile.php
Have you tried opening the create-account-and-profile.php page simply by typing the URL into your browser? If you can't reach the page that way the problem is probably not connected to the POST request.
I think that not possible with wordpress since wordpress will route all http request to wp-content using internal functions of via httacess.

URL repeats itself, leading to a 404 error

My page will redirect the user to another page which will handle all the updating information. I got the redirect in itself working, problem is, the URL isnt what i expect it to be, leading to a 404 error. Let me try to exemplify.
The user clicks a button, redirecting him to "test.com/main/update.php". But my file is in "test.com/test/RazorFinger/update_test.php". so it ends up being something like this:
<FORM name=form id="form" action="test.com/main/update.php?area=<?=$GetArea?>&etc..." method="POST" target='_blank'>
So my main URL is this:
http://test.com/teste/RazorFinger/update_test.php?area=TestArea&proj_id=1234&task_uid=1
And the redirected url is basically:
http://test.com/teste/RazorFinger/test.com/main/update.php?area=TestArea&etc..etc..etc..
The question might be a bit complicated because i'm using fake URLs as example, but basically, i can't get out of "test.com/test" and into "test.com/main", and that leads me to a 404 error. So what's wrong?
put http:// (or https:// if you use SSL) in font of the url.
<form action="http://test.com">
This will lead to the URL http://test.com
<form action="test.com">
This will lead to the URL http://test.com/test.com
you are passing the whole url in the action so this code will obviously give an error.
Replace action by action="test.com. u will get correct result

how to manage the use of both $_SERVER['PHP_SELF'] in action of form and htaccess for urlrewriting together for same page?

how to manage the use of both $_SERVER['PHP_SELF'] in action of form and htaccess for url-rewriting?
If I submit a form and in the action attribute of it i pass "$_SERVER['PHP_SELF']" and at the same time i am using url rewriting for the same page.. then these two things will contradict each other resulting in the display of action value of form in address bar.. so how can i manage this to get the url rewrited form of $_SERVER['PHP_SELF']?
here the rewrite rule is to change the name of url file likewise as if form is submitted to any file say direction.php then rewrite will change it to something 30/redirect.html
I am not sure what rewrite setup you have got so my guess is you have to specify the url in form action. You'd not be able to use $_SERVER['PHP_SELF'] as it will return the path of file which is actually being executed.
For example:
<form action="'.$_SERVER['PHP_SELF'].'">
to
<form action="'./url/as/per/rewrite'].'">
If this doesn't serve the purpose. You can have a look at $_SERVER['REQUEST_URI'] or
$_SERVER['REDIRECT_QUERY_STRING']
$_SERVER['REDIRECT_URL']
and update the form action value.
I hope it helps.

Categories