Jump to content

Value is always false/null when submitting a form


Kazlaaz

Recommended Posts

I'm having trouble getting my if(isset($_POST['form_sub'])) to validate true when submitting a form, where the form name is 'form_sub'. The value always seems to validate as false or NULL. I've tried using a hidden input field also. Basically when I hit submit or enter, with information typed in the first field or all the fields, the result is never true, so it just loops back around to the beginning.

I am using PHP5, Firefox and IE browers. Not sure what other information would be useful.

Any help would be appreciated, thank you.


[code]<?php
if (isset($_POST['form_sub']))
{
echo 'Testing Submit:<br>';
echo 'header: '.$_POST['header'].'<br>';

exit;
}
?>

<?php
if (isset($_GET['add']))
{
?>
<form name="FormName" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="500"  border="0" cellspacing="1" bgcolor="#000000">
  <tr bgcolor="#FFFFFF">
    <td width="150">News Header </td>
    <td><input name="header" type="text" /></td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td>News Headline </td>
    <td><input name="headline" type="text" /></td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td>News</td>
    <td><textarea name="news"></textarea></td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td><input name="featured" type="checkbox" value="1" />
      Featured
      <input name="active" type="checkbox" value="1" />
      Active </td>
    </tr>
  <tr bgcolor="#FFFFFF">
    <td>&nbsp;</td>
    <td align="right">
    <input name="form_sub" type="submit" value="Submit" /></td>
    </tr>
</table>

</form>
<?php
}
else
{
?>
<a href="<?php $_SERVER['PHP_SELF']; ?>?add=1">Add news item</a>
<?php
} // end main if
?>[/code]
I don't think submit values post.  You can see what is and what is not posting by doing
var_dump($_POST);
But I wouldn't expect it to post.  If you really need the value form_sub to post, put it in a hidden with whatever value you want.
It seems my settings are wrong somewhere then, it definately does not work for me.

When I use var_dump($_POST); I get this before i submit, and after: array(0)

Then I tried to add a hidden field:
[code]<input name="submitted" type="hidden" value="true">[/code]
And changed the line 2 php code to:
[code]if (isset($_POST['submitted']))[/code]

Still nothing.

When I var_dump($_POST); that I get the same thing before and after the submit button is pushed: array(0)

EDIT: Seems to be my server settings, tried a different server and it works fine. Thanks everyone. Now to figure out what's wrong with my server.

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.