Jump to content

Submit form with POST


raduenea
Go to solution Solved by raduenea,

Recommended Posts

I have a strange situation.

I want to submit a form with POST method but it's not working. It works only with GET.

When I submit with POST nothing show on test.php webpage.

How can this be possible ? Can be a server restriction ?

 

HTML:

<html>
    <body>
    <form action="test.php" method="post">
        <input type="text"  name="ceva">
        <input type="submit" value="go">
    </form>
    </body>
</html>

 

PHP:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


if(isset($_POST['ceva'])) {
    echo $_POST['ceva'];
}

?>

Thanks.

Link to comment
Share on other sites

That is ALL OF THE CODE???

Try to run this code as 'test.php'.

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo "now running test.php script<br>";
if(isset($_POST['ceva'])) 
{
    echo "Ceva is: ".$_POST['ceva'];
}
else
	echo "Ceva is not set<br>";

 

Link to comment
Share on other sites

Add a name= attribute to your submit button.  Let's see what $_POST shows then. Currently the print_r($_POST) is showing you nothing and that can't be.  So perhaps you have 2 test.php scripts and you are running the wrong one.  Put something into the one you think is being run and let's see if it shows up on your screen.

Edited by ginerjm
Link to comment
Share on other sites

2 hours ago, raduenea said:

The results with this script is

image.png.4152e6ea60bf59d379deb9cbc7e7f3d0.png

these type of problems, where it looks like the code should technically work, are often due to copy/pasting code found on the web, where it has been published and the characters, due to the character encoding being used, aren't actually what they appear to be, or someone typing non-ascii characters as part of the syntax (the base characters for the actual syntax must be straight ascii characters.)

what does changing the print_r($_POST) to print_r($_GET) show, i.e. the default form method is get when an unknown value is used for the method attribute? you can also add echo $_SERVER['REQUEST_METHOD']; at that point in the code to see what the browser is submitting the data as.

if this shows get data/get method, delete and TYPE the entire method='post' attribute (you may in fact need to delete and re-type the entire <form ...> tag if there are some non-ascii characters in it.)

btw - your form and form processing code should be on the same page. this will result in the simplest code and the best User eXperience (UX.) 

 

 

Link to comment
Share on other sites

And also - when you post code here it is highly recommended that you copy and paste (we know that you know how that's done) it here instead of putting up pictures of it.  That way we can more easily view it and if we want to, we can copy it and edit it and place it back if it needs to be done.

Link to comment
Share on other sites

We develop de code on our local machine witch working fine. Actually the code it's much more complex. But when we put it on the server we identify that no POST was made. So when I create that small piece of code just to test the POST and to write it here.

So that small code it's:

index.html

<html>
    <body>
    <form action="test.php" method="post">
        <input type="text"  name="ceva">
        <input type="submit" value="go">
    </form>
    </body>
</html>

 

test.php

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo "now running test.php script<br>";
echo $_SERVER['REQUEST_METHOD'] . '<br>';
if(isset($_POST['ceva'])) 
{
    echo "Ceva is: ".$_POST['ceva'];
}
else
{
	echo "Ceva is not set<br>";
}

 

The results:

now running test.php script
GET
Ceva is not set

 

Something it's wrong. In html I used post method but the server request GET.

Can be server restrictions ?

Thanks

 

Link to comment
Share on other sites

I modify the html code as below. Replace the submit button to force the post, but no success. The same result, server request is GET.

<html>
    <body>
    <form method="POST" action="test.php">
        <input type="text"  name="ceva">
        <button type="submit" formmethod="post" formaction="test.php">Submit</button>
    </form>
    </body>
</html>

 

Link to comment
Share on other sites

Let's try something.  I am by no means a PHP expert nor do I know anything about installations of it but I see this setting in my phpinfo and I wonder what you have there.

In the test.php script add this line:

        print_r(phpinfo());

Then look at the output in the CORE section.   Tell me what the setting is for "enable_post_data_reading".

Link to comment
Share on other sites

3 hours ago, ginerjm said:

Let's try something.  I am by no means a PHP expert nor do I know anything about installations of it but I see this setting in my phpinfo and I wonder what you have there.

In the test.php script add this line:

        print_r(phpinfo());

Then look at the output in the CORE section.   Tell me what the setting is for "enable_post_data_reading".

enable_post_data_reading it's ON for both Local and Master value

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.