<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...
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):
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:
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:
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....
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.
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.
i got your points. your solution has solved my problem. i'd learnt a new knowledge from this. thanks...