cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with form submit - was working before

ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Problem with form submit - was working before

I have a problem with form submission. I've made a minimal example to see if anyone can see the problem. It worked last week before the upgrade:

<?php
if(!isset($_POST['submitCheck']))
{
  // show form
?>
<html>
<body>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input name="submitCheck" type="hidden" value="sent" /> 
    <input name="submit" type="submit" value="Submit" /> 
  </form>
</body>
</html>
<?php 
}
else
{
  echo 'form sent';
}
?>

'submitCheck' always returns false and so the form always shows. Any ideas?
5 REPLIES
Superuser
Superuser
Posts: 9,926
Thanks: 1,265
Fixes: 71
Registered: ‎06-04-2007

Re: Problem with form submit - was working before

I think the suggestion in the long thread here might help explain the problem. But note that there are important follow up posts later in the thread.
Once you have this working a post here to explain what you did would be helpful.
David
David
ratbag
Grafter
Posts: 369
Registered: ‎01-08-2007

Re: Problem with form submit - was working before

Thanks a lot David.
The link you provided says the problem is with 'PHP_SELF' and it is. It suggested trying 'SCRIPT_URL'. I quick search suggests it should say 'SCRIPT_URI' but this led me to 'SCRIPT_NAME' which works (currently anyway). If this is not a good idea for any reason I'll just hard-code the file name. Thank again,
Barry.
Superuser
Superuser
Posts: 9,926
Thanks: 1,265
Fixes: 71
Registered: ‎06-04-2007

Re: Problem with form submit - was working before

Thanks for the feedback.
'SCRIPT_NAME' includes the /~username prefix, but if it works OK with this variable that's fine. It should have worked with 'SCRIPT_URL' which is the relative path from the HTTP root, excluding the /~username prefix.
David
David
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: Problem with form submit - was working before

Quote from: ratbag
this led me to 'SCRIPT_NAME' which works (currently anyway).

That's confusing me because, as David mentions, _SERVER["SCRIPT_NAME"] will contain the /~username. It would work with GET, but not POST.
Gabe
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: Problem with form submit - was working before

$_SERVER['SCRIPT_URL'] is the correct one to use. We are also looking in to getting it working with PHP_SELF, however if you need the script working ASAP it's best to use SCRIPT_URL.