|
-
May 5th, 2003, 07:42 PM
#1
Thread Starter
New Member
html form, dropdown list, populate links with msql, php, js - links extra characters?
This seems to be a tough one, I have not found a solution elsewhere...so...here goes...
I have a form that includes a dropdown list of links that are to be populated from a mysql database. Sound simple enough?
The following code will produce:
http://www.google.ca/?member_link=ht...Fwww.google.ca
if www.google.ca is in the mysql database for $member_link
PHP Code:
<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 have tried stripping the link from the "?" on with php, which I don't think works because of the way the javascript creates the link. There are more details here:
http://www.codingforums.com/showthre...threadid=19457
and
here:
http://forums.webdeveloper.com/showt...6249#post46249
More details here:
-
May 6th, 2003, 03:26 AM
#2
Why do you get that stuff into the database in the first place? I think that is where you need to solve the problem.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 6th, 2003, 09:49 AM
#3
Thread Starter
New Member
not a database issue...
That is what I thought too, something is wrong between the mysql table and the output, but no - if I comment out all the form related tags/script - I get:
www.google.ca
from the
$member_link variable in the mysql loop.
I think the source of the problem is here:
PHP Code:
onsubmit="this.action=member_link[member_link.selectedIndex].value"
That is creating the odd characters I think, and I expect javascript is the best way to take them out - unfortunately I know extremely little about javascript.
still working on it...
-
May 6th, 2003, 10:33 AM
#4
Oh, I understand now what happens.
Finally...
Remove the "name" attribute from the select box.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 6th, 2003, 11:47 AM
#5
Thread Starter
New Member
so close....
That gives me:
http://www.google.ca/?
Which is bloody close, BUT:
The value= attribute gets lost, that is, it does not increment down the pulldown list. All elements in the pulldown end up with the same link property.
Thus, if I had link labels like:
php.net
vbforums.com
google.ca
They would all get www.php.net as their link value.
I like that you are working at the source of the problem.
Others are suggesting I simply strip everthing right of the ? - but I am not sure how.
suggestions?
-
May 6th, 2003, 12:37 PM
#6
Just for S'n'Gs, check the source HTML (not hte source PHP, but the HTML once the page has run) and make sure that what's in the select & option tags is correct. I think that will help determine where the problem goes screwy.
I GET IT KNOW! I see what you are trying do and possibly why it doesn't work....
The first problem is that you are passing the form as a GET, which means all the form values awill be passed through the URL ... this is why you got the funky "?member_link=http%3A%2F%2Fwww.google.ca", the form wanted to pass the value of member_link in the URL.
The other half of the problem is you are changing the "action" of the form... but at the sametime, it is still set to GET. so it adds the "?"to the end ready for parameters.
Still, this isn't what you want.
Here's what you should do IMHO:
1) Create a new page called goto.php
2) Put PHP code into it to read the querystring
3) perform a redirect (I forget the actual name of it in PHP, but it shouldn't be too hard to find), using the passed in member_link parameter
4) Remove the "on_submit" event from the form, and add the Action to point to the new "goto.php" file.
That, I think will help.
-
May 6th, 2003, 02:03 PM
#7
Thread Starter
New Member
okay...
That is a tall order .
Just for fun, the form outputs as hoped,
PHP Code:
<form name="member_links" target="_blank" method="get" onsubmit="action=member_link[member_link.selectedIndex].value">
<!-- onsubmit="action=member_link[member_link.selectedIndex].value" -->
<select name="member_link">
<option value="http://www.flashbackalternatives.com">80s web radio</option>
<option value="http://www.mysql.com">mysql</option>
<option value="http://www.php.net">php</option>
<option value="http://www.google.ca">google</option>
</select>
<input type="submit" value="Go">
</form>
It is how it gets submitted that messes things up - rock and a hard place - using javascript with html form to 1) create the right links in the page output, but at the same time 2) submit them appropriately. Seems I can get either, not BOTH at this point.
I think I understand what you are saying, and though it seems overly complicated for what started out to be a conceptually simple idea, I will likely try it just to say I did it...
-
May 6th, 2003, 04:01 PM
#8
Thread Starter
New Member
techgnome is my hero.
Kudos to techgnome.
It was actually far less complicated that I expected using your method since the link did not need any alteration as it gets sent as 'member_link' from the form and can be called from the $_REQUEST array with php.
Hence the working version looks like this:
FORM
PHP Code:
<form name="member_links" target="_blank" method="get" action="member_link_url_redirect.php?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_database = $myrow["Link"];
$link_label = $myrow["Link_Label"];
$name = $myrow["Name"];
?>
<option value="<?php echo 'http://'. $member_link_database; ?>"><?php echo $link_label; ?></option>
<?php
}//end while
?>
</select>
<input type="submit" value="Go">
</form>
member_link_url_redirect.php
PHP Code:
<?php
$link = $_REQUEST['member_link'];
header("location: ". $link);
?>
I am sure there are other solutions, but I think I have spent too much time on this already - thanks again techgnome *flutter eyelids*
-
May 6th, 2003, 04:05 PM
#9
Yeah, it sounds a lot more complicated than it really is....
-
May 6th, 2003, 04:42 PM
#10
action="member_link_url_redirect.php?member_link[member_link.selectedIndex].value"
You can savely truncate this to
action="member_link_url_redirect.php"
it won't make any difference.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 6th, 2003, 05:09 PM
#11
Thread Starter
New Member
right.
yes, thanks, CornedBee
I actually had done than in the final version, realized I didn't need it since everthing is now out in the mysql loop.
cheers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|