1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

send hidden key with a link...

Discussion in 'PHP' started by chxxangie, Sep 24, 2007.

  1. #1
    
    <form name="form1" method="post" action="request_infor_form.php">
       <input name="key" type="hidden" id="key" value="1">
       <input type="submit" name="Submit" value="Request Information">
    </form>
    
    PHP:
    above code is a button that hold a hidden key and submit to the next page.

    i wish to replace the button with text.

    
    <form name="form1" method="post" action="request_infor_form.php">
       <a href="request_infor_form.php">
       <input name="key" type="hidden" id="key" value="1">
       Request Information</a>
    </form>
    
    PHP:
    but i don't know how to let it hold the hidden key...the code i write seems doesn't work... :(
     
    chxxangie, Sep 24, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    I forgot... someone here will know, but if not, you can use this, better than nothing:

    <script type="text/javascript">
    document.write('<a href="#" onclick="this.form.submit();">Request Information</a>');
    </script>
    <noscript>
    <input type="submit" value="Request Information">
    </noscript>
    Code (markup):
     
    krt, Sep 24, 2007 IP
  3. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    The A Href won't submit the form, it will only serve the PHP again.

    I do as follow, which allows you to submit your form with different object inside the form.
    
    <script language="Javascript">
    function jssubmit()
    {
      document.GetElementById("key").value = whaeveryouwant;
      document.GetElementById("form1").submit;
    }
    </script>
    
    <form id="form1" name="form1" method="post" action="request_infor_form.php">
    <a href="Javascript: jssubmit();">Request Information</a>   
    <input id="key" name="key" type="hidden" id="key" value=<?php echo $_POST['key']; ?> 
    </form>
    
    
    
    HTML:
     
    webrickco, Sep 24, 2007 IP
  4. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    still cannot...it show below there...."Error On page."
     
    chxxangie, Sep 24, 2007 IP
  5. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I made a couple of small changes to webrickco's code:

    
    <html>
    <head>
    <script language="Javascript">
    function jssubmit()
    {
      document.form1.key.value = 'secret value';
      document.form1.submit();
    }
    </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <a href="" onclick="jssubmit(); return false;">Request Information</a>   
    <input id="key" name="key" type="hidden" id="key" value="<?php echo $_POST['key']; ?>" />
    </form>
    </body>
    </html>
    
    HTML:
     
    sea otter, Sep 24, 2007 IP
    yyyk9 likes this.
  6. yyyk9

    yyyk9 Peon

    Messages:
    670
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #6
    What is the purpose of this?
     
    yyyk9, Sep 24, 2007 IP
    sea otter likes this.
  7. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Heh, I was wondering the same thing.
     
    sea otter, Sep 24, 2007 IP
  8. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    the purpose is....i don't want to put button there...
    replace the button with the link....
     
    chxxangie, Sep 25, 2007 IP
  9. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    beside of changing this line, (my hidden key is holding value 1)
    document.form1.key.value = '1';
    what else need to change? because the hidden key have not pass to next page....
     
    chxxangie, Sep 25, 2007 IP
  10. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #10
    If the ACTION of the form is equal to the php page you want to submit to, and if you echo the value of the POST of key there, then it will display its value.

    echo $_POST['key'];
    PHP:
    should contain the value stored by the javascript function. (Tip: for testing purposes use a text field instead of a hidden field, this will validate the correct work of the js function. The Name of the object if mandatory, and should be unique (otherwise it's an array))

    I use
    document.getElementById('key').value
    Code (markup):
    instead
    document.form1.key.value 
    Code (markup):
    upon recommandation of w3c norms. It permits to states fields independently of the form containing them, it requires however a unique ID declaration to work.

    If you continue to have problems with that please Post the code of the submission script so that we can help better.
     
    webrickco, Sep 25, 2007 IP
  11. W-Shadow

    W-Shadow Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Why not just use
    <a href="request_infor_form.php?key=1">Request Information</a>
    HTML:
    and modify the php script to use $_GET or $_REQUEST instead of $_POST?

    A possible objection would be that the key wouldn't be "hidden" anymore, but it wasn't really hidden anyway - it's right there in the HTML. If you want it to be really hidden, you need to design your application differently.
     
    W-Shadow, Sep 25, 2007 IP
  12. chxxangie

    chxxangie Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12

    i got your points. your solution has solved my problem. i'd learnt a new knowledge from this. :D thanks...
     
    chxxangie, Sep 25, 2007 IP
  13. yyyk9

    yyyk9 Peon

    Messages:
    670
    Likes Received:
    52
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Wait, what is this script used for, in the real world?
     
    yyyk9, Sep 26, 2007 IP