I have a really annoying problem.
I have a form and when I Submit it it doesn't set the post.
<form action="pages/post-reply" method="post">
<div class="row">
<div class="large-12 columns">
<textarea name="comment" placeholder="Comment on admin"></textarea>
</div>
</div>
<input type="submit" name="submit" class="tiny button" value="Post"/>
</form>
I use a framework called Processwire and Foundation but I don't think this has anything to do with it.
When I try it out on my webserver (a dedicated host) it works. I am using a WAMP install on Windows 8. Could this have anything to do with it?
When I use:
echo $_SERVER['REQUEST_METHOD'];
It just says:
GET
Edit: .htaccess file:
http://textdump.net/raw/2212/
Still not any progress, does anyone know if it might be Wamp or Windows 8 screwing this up?
This may be caused by redirection either from the page of pages/post-reply itself or .htaccess rule on the root directory who is redirecting the request pages/post-reply as a GET Request.
Check your .htaccess rule
According to your .htaccess file, this is the line that is redirecting your request to a different URL
RewriteRule ^(.*)$ index.php?it=$1 [L,QSA]
However, modifying this rule will probably crack your application, so basically what happens is the request gets send to the script as
index.php?it=pages/post-reply
So may be this is help you solve further.
I know this is a very old question, but the right answer might just benefit someone. The first line should read.
<form action="<?php echo $config->urls->templates ?>pages/post-reply" method="post">
See http://cheatsheet.processwire.com/ for details.
Related
I'm a bit confused about this. I'm hoping it's something wildly obvious I've missed! I have a very simple form:
<form class="form-signin" role="form" name="login" method="POST" action="/page">
<input type="password" name="password" />
<input type="submit" value="Sign in" />
</form>
Note: this page lives at /page and is echoed after the following HTML:
On /page I have this at the very top of the file:
<?php
var_dump($_SERVER['REQUEST_METHOD']);
For some reason, it always shows up as GET when I submit this form. If I take the action="/page" part out then it shows up as POST. What am I missing here?
Note: Even when I load the page, then put at exit after the above var_dump() call, it still shows GET.
In the inspector's timeline I see this for the request:
Thanks to the comments to my question I have found the answer to be in apache configuration. It appears that, because the index.php file is inside a folder called page, apache will automatically redirect to the page with a slash on it. This is the default setting as seen in the Apache directorySlash documentation.
As they warn against turning this off, I will just change the url to what I'm posting. Alternatively, of course, I could add a .htaccess file with proper rewrite rules setup.\
Thanks for everyone's help! As a side note, Safari's inspector left me a little wanting in this case. Chrome turned out to be a far better option for testing.
<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
This code should print whatever is enter in text box name="ss" when click submit.
But its not printing. Working with method="get" but not with post, What's the problem.
If you're just refreshing the page, do:
action=''
instead of:
action="<?php echo $_SERVER['PHP_SELF'];?>"
Also, add this to line 2 to see what's being stored (if anything) in the $_POST array:
var_dump( $_POST );
Hmm... so it's empty on submit? Try adding this to the top of your php file:
if(empty($_SERVER['CONTENT_TYPE']))
{
$_SERVER['CONTENT_TYPE'] = "application/x-www-form-urlencoded";
}
Okay, now check your php.ini (normally requires sudo or root in /etc):
post_max_size = 8M
variables_order = "EGPCS"
Do you have those two rules set? If so, be careful of how much memory you're allocating. Anything over 2048MB could start to give you trouble, depending on your system specs.
NOTE: If you make changes to your php.ini file and PHP is running as an apache module, you'll need to restart apache. Something along the lines of:
sudo /etc/init.d/httpd restart
I broken my post method once that I set post_max_size the same with upload_max_filesize.
I think that post_max_size must less than upload_max_filesize.
Tested with PHP 5.3.3 in RHEL 6.0
It may be due to rewrite rules in the .htaccess file.Add this condition to your .htaccess file
RewriteCond %{REQUEST_METHOD} !POST [NC]
OR add this line
RewriteRule ^welcome_post.php - [PT]
Finally ...Got it.... Firstly I have an Article folder in my htdocs file with welcome.php as the php file in focus and a main HTML file , whose contents we will be discussing about.
Here's what worked for me..
Turns out the problem was not XAMPP or any of its related files..
The problem was this :
<form action="welcome.php" method="post">
With this code whenever I pressed the submit button, the url redirects to here file:///C:/xampp/htdocs/Article/welcome.php, Which is not what it needs to be..It has to be a localhost link ..So I changed the value of action attribute to localhost form and now it looks like this
<form action="https://localhost/Article/welcome.php" method="post">
That did the trick..Now the submit button redirects to https://localhost/Article/welcome.php , this link..Which is exactly what is needed..
Remember the browser may ask you for some permission issues ..Just accept them it will run fine...
Best of luck..
P.S : This one is for Windows..Hope it will work also in Linux and Mac.
My friend ran into this problem today. The answer was pretty simple - basically, you have to capitalize the POST part of method="POST"
The final result should look like
<?php echo $_POST['ss'];?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input name="ss" type="text" />
<input type="submit" name="submit">
</form>
First make sure that your web service (GET/POST etc) is acting as desired using the Chrome Advanced Rest Client. Then you should check your PHP part.
I solved mine with including following into header.
Content-Type: application/x-www-form-urlencoded
Just use this in the header while making a request and my problem was solved.
<form action="" method="post"> method="post" is important for POST Data.
Use PHP REQUEST instead:
<form action="" method="post">
<input type="email" name="mail">
<input type="submit" name="submit" value="Submit">
</form>
PHP:
if(isset($_REQUEST['submit'])){
$val= $_REQUEST['mail'];
echo $val;
}
use this instead;
$variable_name = $_REQUEST["ss"];
echo $variable_name;
change your IDE ,i use phpstorm ,it's fantastic but when i use dreamweaver it works probably, for test you can run your page directly from wampserver localhost , i change default port of apache and i think problem is from there , if you use phpstorm or change port of apache server change your IDE.
I'm try to post in a hidden input a base64 encoded image (~ 500KB) and all I get is an error
501 Method Not Implemented
GET to /test.php not supported.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
my code
<?php error_reporting(E_ALL) ?>
<html>
<head></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<input type="hidden" name="image" value="{base64 encoded image}">
<input type="submit" name="" value="OK">
</form>
<?php if($_POST) {
echo '<pre>'.print_r($_POST, true).'</pre>';
} ?>
</body>
</html>
Ps. on localhost everything works fine.
Thanks for help.
This is probably due to security issues. Try this:
To fix this, add this to your /etc/httpd/conf/httpd.conf, inside the block that starts with (the path of the root of your Apache directory tree):
SecRuleEngine off
<Directory "/var/www/html">
SecRuleEngine off
</Directory>
/var/www/html is the DOCUMENT_ROOT of your site. Restart/reload apache.
Assuming you're using the same browser it may be the post_max_size php.ini setting, although I would think it would be set much higher than ~500KB by default.
Looking at the error message, there are two issues. One is a 501, one is a 404.
The 501 is because your web server isn't recognising the POST method. Try it with post in lowercase (although i'd be surprised if that caused an error).
The 404 is because the target of the form isn't being found (or it might be misconfigured) and there is no ErrorDocument set up to handle 404's. Have a look at the html of the form in your browser and make sure that $_SERVER['PHP_SELF'] is outputting the correct URI.
If neither of these seem odd, try posting the form without any image data. It might be that you need to encode the data for POST transport.
I'm tying to send POST data from one site to another (both sites have been developed by us).
The problem is that the POST variables are not available if the page is requested from another domain.
Even if I test it locally, but specify the complete url, the POST data is gone.
So, this will work:
<form method="POST" action="test.php">
But this will not:
<form method="POST" action="http://example.com/test.php">
Here is the HTML for the page:
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="http://example.com/test.php">
<input type="text" name="request" value="" id="" />
<input type="submit" value="" id="" />
</form>
</body>
</html>
After the comments I got that this should work, I tested it on another server and there everything worked fine indeed. This might have something to do with the fact on the first server https is enabled. But if this is the case, I find it strange that I do get information back but that just the POST data has gone missing.
What you have should work fine - forms came before the same-origin policy - you're allowed to submit to different domains.
If I were to hazard a guess, I'd say there's a 301 or 302 redirect getting in there somehow? Follow the HTTP headers with Firebug for example to be sure.
As others have said, there should be no problem doing this. I would suggest replacing your test.php script with something simple, like this
<?php
echo "<pre>";
var_dump($_POST);
echo "</pre>";
You should find it works, which means the blame lies somewhere in the "real" script...
Maybe also a timesaver:
If you POST to domain.com make sure it doesn't get redirected to www.domain.com.
The redirect doesn't take the POST variables into account , only GETvariables.
If it does get redirected to the www.domain.com add the www. in your POST-action
Thank you. I too found out that redirection to www and https was blocking the performance of my $_POST request.
By changing my action to include https://www.
I fixed my problem.
Thank you
I have a CodeIgniter project with a very simple test application.
Controller opens a view (PHP page) which has a text box and a submit button.
When I press the submit button, instead of redirecting to the appropriate function call in the controller, I get redirected to localhost/xampp.
here's the code on my view, which SHOULD be redirecting to the save_genre function in the controller named "welcome".
<?php echo form_open('welcome/save_genre');?>
<label for="radio_genre">Radio Genre</label>
<input type="text" name="radio_genre" id="radio_genre"></input>
<?php echo form_submit('submit','Save'); ?>
</form>
any ideas what could be wrong? I think it's not the code but is a setting or file wrong somewhere, but i don't know where to start looking.
EDIT:
I had already redefined the base URL in the config file.
I don't think I rewrote the .htaccess - but I'll certainly check. (This is a team project setup and I'll make sure no one else has done that.)
As requested, below is the HTML output by the form. The URL link for the form seems very odd to me because it doesn't mention the project name like I would expect. So there are two places for me to look now. Thanks!
<body>
<h1>Welcome!</h1>
<form action="http://localhost/index.php/welcome/save_genre" method="post">
<label for="radio_genre">Radio Genre</label>
<input type="text" name="radio_genre" id="radio_genre"></input>
<input type="submit" name="submit" value="Save" />
</form>
</body>
EDIT: OK - I recreated the project myself and then brought my PHP files in and it works fine. So the person who created the project did something odd.
You need to edit $config['base_url'] in /system/application/config/config.php.
Somehow, while the index.php file was there in the file system, it wasn't being recognized as part of the project. Once I copied a new index.php file in there (identical file but it trigger the sense that "this changed.), I then went back into my project and refreshed and saved.
Everything then worked.