Jump to content

Sending Post data using hyperlink


Fed196

Recommended Posts

Hello:

 

I am new to html, php, mysql and need help.  I'm not sure if this is an html or javascript question.

 

I would like a recipe index page that lists all recipes as hyperlinks.  By clicking on the hyperlink, it will pull up the full recipe displaying recipe name, ingredients and instructions.  I have handled this with a test form, entering the recipe name as text, and clicking on a submit button.  It works perfectly.  However, I would like to use hyperlinks, instead.  With the form below, if I use one hyperlink, it works fine.  However, with 2 or more hyperlinks, it does not work.  What am I doing wrong?  Any assistance would be greatly appreciated!

 

Thank you.

Karen

<html>
<head>
<title>Form16 April 11</title>
</head>
<body style="background-color:cyan">

<h2 style="text-align:center">Recipe Index </h2>

<hr>

<script language=javascript>
function submitPostLink()
{
document.postlink.submit();
}
</script>
</head>
<body>
<form action="test5.php" name=postlink   method="post">
<input type="hidden" name="recipe_name" value="Anise Pizzelles">

<a href=# onclick="submitPostLink()">Anise Pizzelles</a>
<br>

<input type="hidden" name="recipe_name" value="Tea Cookies">
<a href=# onclick="submitPostLink()">Tea Cookies</a>
<br>

</form>

<hr>
</body>
</html>

 

edit: added


blocks

Link to comment
https://forums.phpfreaks.com/topic/234590-sending-post-data-using-hyperlink/
Share on other sites

in the example you are using you have two hidden fields with the same name. which will always use the second hidden field's value. You may need to rethink the way you are doing this.

 

Why don't you just use GET in your script instead of POST. If you did this you could simply link to test5.php?recipe_name=Tea%20Cookies etc. Otherwise you will need to change the value of your hidden input field when the user clicks the link. Like so:

<html>
<head>
<title>Form16 April 11</title>
</head>
<body style="background-color:cyan">

<h2 style="text-align:center">Recipe Index </h2>

<hr>

<script language=javascript>
function submitPostLink(obj)
{
document.getElementById('recipe_name').value=obj.innerHTML;
document.postlink.submit();
}
</script>
</head>
<body>
<form action="test5.php" name=postlink   method="post">
<input type="hidden" id="recipe_name" name="recipe_name">

<a href=# onclick="submitPostLink(this)">Anise Pizzelles</a>
<br>
<a href=# onclick="submitPostLink(this)">Tea Cookies</a>
<br>

</form>

<hr>
</body>
</html>

 

Also, when posting any code, please use the


blocks to wrap it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.