Action perform with mouse click on button and not with keyborad enter

Discussion in 'PHP' started by babaMBA, Aug 22, 2007.

  1. #1
    <form id="frmAddCat" name="frmAddCat" method="post" action="<?php echo $PHP_SELF; ?>">
    Enter Catagory Name:
    <input name="catName" type="text" id="catName" />
    <input type="submit" name="Submit" value="Add" />
    </form>

    <?php
    if( $_POST['Submit'])
    {
    echo ("Submit button click");
    }
    ?>

    I am using this code but this code has a big bug.

    When the page is open the "if" block execute only with the mouse click on submit button.

    If user filled out the catagory name and press enter then the "if" block cannot execute.

    How can i solve this.
     
    babaMBA, Aug 22, 2007 IP
  2. techMonster

    techMonster Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Instead of using

    if( $_POST['Submit'])

    try to use this

    if( $_POST['catName'])

    or

    if( !empty($_POST['catName']))

    and it should work.
     
    techMonster, Aug 23, 2007 IP