user3415003
user3415003

Reputation: 27

switch from the $get method to $POST

OK this "should" be a simple code but i got really stuck on this... I usually deal with forms that uses the $GET method, but for this one i need to go with the $POST.... so i want to take this code and put it into a $Post

    $display_string .= "<th><a href='Details.php?ID=".$row[ID]."'>".$row[Name]."</a>";

This is a line from a dynamic table that i am fetching data from using ajax, but i then want to take this user data and fill a user_Detail page....using the $POST

Can anyone trow me a line here????

Thanks

Upvotes: 0

Views: 225

Answers (2)

muri
muri

Reputation: 265

Links aren't supposed to send POST requests. Anyways, you can do it by using a hidden form and a link that triggers a javascript.

$display_string .= "<th><form action='Details.php' id='detailsForm". $row['ID'] ."' name='detailsForm' method='POST'><input type=hidden name='ID' value='" . $row['ID'] ."'></form><a href='#' onclick=\"document.getElementById('detailsForm". $row['ID'] ."').submit();\">". $row['Name'] ."</a>";

Should do the trick. Create a form, insert the value you want to submit in a hidden input field and the link triggers the form to be submitted onclick.

EDIT: If you meant ID and Name to be a constant, of course you have to write $row[ID] and $row[Name] instead of $row['ID'] and $row['Name'].

EDIT: so give every form a unique ID (like the $row['ID'] and tell the javascript to submit exactly this form.

Upvotes: 1

xate
xate

Reputation: 6379

You have to use a form then.

<form action="Details.php" name="display_string" method="POST">
    <input type="text" name="ID" value="$display_string" /> 
    <input type="submit" value="Submit">
</form>

Upvotes: 2

Related Questions