Search code examples
phphtmlarrayshidden-field

PHP isset not accepting form name


I am having an issue trying to get my form with a hidden input field to be recognized when I check if it isset. Not sure if it is because I am running the form in a loop or what. I do know when I click submit for any of the fields from the loop the value of the hidden field is registering properly, it is just somehow the 'form1' is not registering as isset. Any ideas?

<?php
if(isset($_POST['form1']))
    {
    echo $_POST['cid'];
    } else {echo "nope!";} 
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" name="form1">
// gets array
$listchars = $user->getCharacterList($_SESSION['user_id']);
// loops through array 
foreach($listchars as $chardata){
 echo $chardata['name']; ?>
<input type="hidden" name="cid" value="<?php echo $chardata['cid'];?>">
<input type="submit" name="submit" value="submit">
<?php } ?>
</form>

Solution

  • The form name is not submitted

    Use

    <input type="submit" name="form_name">

    or

    <input type="hidden" name="form_name">