PDA

View Full Version : onsubmit, form, array, dropdown, link - remove variables


mr_fitz
05-05-2003, 07:20 PM
I have a form that includes a dropdown list of links that are to be populated from a mysql database.

The following code will produce:

http://www.google.ca/?member_link=http%3A%2F%2Fwww.google.ca
if www.google.ca (http://www.google.ca ) is in the mysql database for $member_link

<form name="member_links" target="_blank" method="GET" onsubmit="this.action=member_link[member_link.selectedIndex].value">
<select name="member_link">
<?php
$SQL = "SELECT * FROM member_links WHERE Name = '$membername' ORDER BY Link_Label ASC";
$result = mysql_query($SQL);
while ($myrow=mysql_fetch_array($result)) {
$member_link = $myrow["Link"];
$link_label = $myrow["Link_Label"];
$name = $myrow["Name"];
?>
<option value="<?php echo ('http://'. $member_link); ?>"><?php echo $link_label; ?></option>
<?php
}//end while
?>
</select>
<input type="submit" value="Go">
</form>


QUESTION IN A NUTSHELL:
How do I get rid of the:
?member_link=http%3A%2F%2Fwww.google.ca
part of each link in the drop down menu?

I realize I have redundant code here, I know so very little about javascript and forms - I have been trying different variations for hours and cannot get anything to work.

JohnKrutsch
05-05-2003, 08:21 PM
I would do it on the PHP side:

<option value="<?= 'http://'. substr($member_link,0,strpos($member_link,"?")); ?>"><?= $link_label; ?></option>

This should remove the ? and anything after it.

mr_fitz
05-05-2003, 09:15 PM
I hadn't thought of just stripping the link output...I was focussing on the "source" of the problem, the onsubmit fuction.

Unfortunately, what you have given me produces everything after the ?, not before it - e.g.:

http:///?member_link=http%3A%2F%2F

working on how to flip this around and get everything before the ? - if you want to help me out, great...(though this is not a php forum)

Just appending this...
It seems that this MAY not be the solution.
The following code produces the output:
http://www.php.ne/?member_link=http%3A%2F%2Fwww.php.ne
<option value="<?php echo 'http://'. substr($member_link,0,10); ?>"><?php echo $link_label; ?></option>
(I simply replaced the strpos with "10". It seems the link is being output twice unnecessarily)
It may be that my variable names are duplicated...use of member_link in the mysql loop and in the form.

mr_fitz
05-05-2003, 11:47 PM
I really don't know what to do...anyone got ideas?

JohnKrutsch
05-06-2003, 03:55 PM
Yeah I am going to move this to the PHP forum.

When I test the code I gave you it gives me the front part of the URL:


<?php

$member_link="http://www.google.ca/?member_link=http%3A%2F%2Fwww.google.ca";
echo "$member_link<p>".substr($member_link,0,strpos($member_link,"?"));

?>

mr_fitz
05-06-2003, 08:38 PM
Yes, sure, but $member_link is in the form:

www.google.ca

from a mysql database table, not the garbled version.

It is how the javascript manipulates $member_link through the array and the form that messes it up. It is partially because I have to use GET (instead of POST) whereby the former always passes stuff via ?variables in the url (hence the need to get rid of it).

There is likely a php solution, but the php is not causing the problem per se.

more ideas, please?

I can potentially send url from the form to a separate php page and then do what you suggest and spit it back through some form of automatic redirection to the original page...lots of overhead.

mr_fitz
05-06-2003, 10:02 PM
This links shows a method that works using redirect via php

http://www.vbforums.com/showthread.php?s=&postid=1430390#post1430390