Jump to content

HTML form post fails


megosh

Recommended Posts

Hi, I've got a small problem that has been annoying me for a long while. In short, I've had a few pages that require the user to enter information and it creates an account for them... They work 99% of the time for all users... however, I do get some situations where users experience an inability to submit the page. Basically saying that hitting the submit button does nothing but refresh the page. This does not appear to be browser specific and can usually be solved by restarting the user's browser. (or in chrome opening a new tab)

 

Here is some code from my creation page that has this problem. I edited out all the sql things and replaced it to keep it simple. I have personally experienced the problem stated in about 1 in 100~ tries.

 

<html>
    <body>
    <?php
    if ($_POST['Submit'])
    {
        //do stuff
        echo "information entered: ".$_POST['test'];
    }
    else
    {
        ?>
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
            Test:  <input type="text" name="test">
            <br>
            <input type='submit' name='Submit' value="Submit">
        </form>
        <?php
    }
    ?>
    </body>
</html>

 

Does anyone have any possible insight into the cause of this problem, or what coding style I can adopt to prevent it from happening?

 

All input is appreciated.

 

Kind regards,

 

Doug

Link to comment
https://forums.phpfreaks.com/topic/198081-html-form-post-fails/
Share on other sites

There is:

http://pastebin.com/bZtEWmeA

which is used on every page for an expanding menu

 

http://pastebin.com/mqCNreAC

for an in-window popup (not called on any of my pages containing $_POST)

 

http://pastebin.com/AnkbzqgX

to replace the current in-window popup (not called on any of my pages containing $_POST)

 

http://static.wowhead.com/widgets/power.js

called on almost all pages

I'm not entirely sure what you were asking, so I assumed this:

 

<html> 
    <body> 
            <form action="/test.php" method="POST"> 
            Test:  <input type="text" name="test"> 
            <br> 
            <input type='submit' name='Submit' value="Submit"> 
        </form> 
            </body> 
</html>

 

copy-paste from view-source:http://localhost/test.php

Oops  :o

 

Try changing this:

 

if ($_POST['Submit'])

 

To this:

 

if (isset($_POST))

 

And actually, I'm going to move this to the PHP forum. Your form looks to be properly structured HTML to me, so I'm thinking it's a PHP problem. That section of the forum is much busier than this one, so you are more likely to get the help you need there, though I will still check in to see what happens.

Quick question... Doesn't if($_POST) do the same as if(isset($_POST))?

 

What if I only want one portion of the post, if per-say I'm using multiple <input type='text' name='Test1'> <input type='text' name='Test2'>... Simply checking for if(isset($_POST)) wouldn't do what is required. Then what would the difference be between if(isset($_POST['Test1']) and if($_POST['Test1'])?

 

I'm using both if(isset($_POST['test'])) and if($_POST['test']) in different places, and have experienced the problem with both. I'll try changing them all to isset() and will report back in a day or so.

 

Thanks for the move and the attention.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.