I know that it's kind of wrong to ask a question that's almost been answered in the past, but even though I'm trying to use this solution , it doesn't work.
Basically, I have a php table with a search link created in a HTML button from the strings inside the table.
Let's say that this string is creating a search in the website called Discogs and that the information I'm searching through a created link is the word "Beatles".
www.discogs.com/search/?q=Beatles
You notice the ?q=
Everytime I click on the link through a php code which looks like this, the opened link brings me to www.discogs.com/search/? WITHOUT THE REST OF STRINGS (in that case, the word Beatles)
I tried to rawurlencode the ?
to have it as a %3F
.
Here is what my code looks like
$discogslink = 'http://www.discogs.com/search/'.rawurlencode('?').'q='.'Beatles' ;
$form = "<form action='$discogslink' >";
$form .= "<input type='submit' value='Discogs'>";
$form .= "</form>";
echo '<td class="'.$lps->type.'">'.$form.' </td>';
The link that I would like to open is http://www.discogs.com/search/?q=Beatles
The link that opens is : http://www.discogs.com/search/ ? (nothing after the '?'...)
Do you have any idea why it does that?
BONUS QUESTION : How can I make the button open in a new tab instead of the same one?
The reason for this is the default behaviour of HTML forms. They send data as a GET request, just like links do. So in your case the content of the form (which is empty) overwrites your q-parameter because the form content wins over the parameters specified in the action link.
The solution is to add a hidden field:
<input type="hidden" name="q" value="Beatles"></input>
And concerning the new window:
<form target="_blank" ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.