how to submit the value through links

Discussion in 'PHP' started by kumar84, Aug 24, 2007.

  1. #1
    hi friends

    This is my code

    <img src="pet.jpg"> <a href="#" onClick="getImages()">ADD TO PROFILE</a>


    <form method="post" action="" name="form1">
    <input type="hidden" name="imageurl" value="pet.jpg"/>
    </form>

    <script type="text/javascript">
    function getImages(){
    document.form1.submit();
    }
    </script>

    after calling this java script it is not going inside of my isset functions

    that is i have shown below

    <?
    if(isset($_POST['form1']))
    {
    $link=$_POST['imageurl'];
    //$page="index.php";
    $disp="<img src='$link'>";
    $display.=$facebook->api_client->profile_getFBML($user).$disp;
    $facebook->api_client->profile_setFBML($display,$user);
    echo "The picture has been posted";
    }
    ?>

    now i need after i click add to profile link it should go and perform the function inside
    if(isset($_POST['form1']))
    {

    }
    so what's wrong in my code and what changes i want to do in this code
    can anybody help me
     
    kumar84, Aug 24, 2007 IP
  2. Eps

    Eps Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    add a hidden input
    <input type="hidden" name="form-name" value="form1">
    HTML:
    to the form.

    In the script, replace if(isset($_POST['form1'])) with

    if( ($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['form-name']) && ($_POST['form-name'] == 'form1') )
    PHP:
    As much experience as I've had with forms you can't rely on checking for whether the form name or submit button is passed as part of form data. I also advise you to work around your HTML and Javascript so that it doesn't use the submit() method for the form (its behaviour is unpredictable).
     
    Eps, Aug 25, 2007 IP