Jump to content

Archived

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

Kazlaaz

Value is always false/null when submitting a form

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
i dont understand what you mean is wrong.. i have entered info in the form and submitted and it works.. it prints the header..

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.