468,272 Members | 2,083 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Form to append text to end of choice of URL's

Dan
Hi all-
I am trying to create a simple webpage to save me some time. The
general idea is create a form where I can type in the ticker symbol of
a company (ex: MSFT) and then select a bunch of different sites from
buttons or links to financial sites such as Yahoo Finance, BigCharts,
Routers, etc. Each of those financial sites has a different format for
their URLs such as
http://bigcharts.marketwatch.com/int....asp?symb=MSFT.
What I want to do is take all of these different URLs and just have it
add whatever symbol I choose at the end of them.

I am running into a few problems though. I can create a form to submit
to one site, but I do not know how to have a dozen or so links all use
the input from one text field. Also, I do not now how to code the part
to append the text to the end either. I can pass a variable but it
always includes the "?" which I don't want.

If anyone can provide any help or places to get started I would really
appreciate it! Thank you,
-Dan

Aug 14 '06 #1
6 2526
$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);

// loop through the sites
foreach ( $sites as $url )
{
echo sprintf($url,$_GET['symbol']); // replaces %s with your symbol
}

Aug 14 '06 #2
Dan
I'm sorry I am trying to figure this out and I need a little more help.
I am fairly new to this and while I understand the logic I am not sure
exactly where to place this. Can I just use a regular form? If so, do
I have a separate submit button for each site I want to use? Thanks
again for your help,
-Dan
BKDotCom wrote:
$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);

// loop through the sites
foreach ( $sites as $url )
{
echo sprintf($url,$_GET['symbol']); // replaces %s with your symbol
}
Aug 14 '06 #3
reading your post again I see you don't want the "?" in your urls.
That's a result of using the "get" method with your form (the default)
here's a more complete code for your page:

<?php

$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);

if ( !isset($_POST['symbol']) )
$_POST['symbol'] = '';

?>

<FORM method="POST">
<INPUT type="text" name="symbol" value="<?php echo
htmlspecialchars($_POST['symbol']); ?>" />
</FORM>

<?php
if ( !empty($_POST['symbol']) )
{
// loop through the sites
foreach ( $sites as $name =$url )
{
$url = sprintf($url,urlencode($_GET['symbol'])); // replaces %s with
your symbol
echo '<A HREF="'.$url.'">'.$name.'</A><BR />';
}
}
?>

Aug 14 '06 #4
Dan
That seems to be what I want to do except that the symbol is not being
replaced. I just get an empty end of line
(http://bigcharts.marketwatch.com/int...ames.asp?symb=)


BKDotCom wrote:
reading your post again I see you don't want the "?" in your urls.
That's a result of using the "get" method with your form (the default)
here's a more complete code for your page:

<?php

$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);

if ( !isset($_POST['symbol']) )
$_POST['symbol'] = '';

?>

<FORM method="POST">
<INPUT type="text" name="symbol" value="<?php echo
htmlspecialchars($_POST['symbol']); ?>" />
</FORM>

<?php
if ( !empty($_POST['symbol']) )
{
// loop through the sites
foreach ( $sites as $name =$url )
{
$url = sprintf($url,urlencode($_GET['symbol'])); // replaces %s with
your symbol
echo '<A HREF="'.$url.'">'.$name.'</A><BR />';
}
}
?>
Aug 14 '06 #5
"typo"
I didn't change the $_GET['symbol'] from my frist post to
$_POST['symbol']
make the change and all is well

Dan wrote:
That seems to be what I want to do except that the symbol is not being
replaced. I just get an empty end of line
(http://bigcharts.marketwatch.com/int...ames.asp?symb=)


BKDotCom wrote:
reading your post again I see you don't want the "?" in your urls.
That's a result of using the "get" method with your form (the default)
here's a more complete code for your page:

<?php

$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);

if ( !isset($_POST['symbol']) )
$_POST['symbol'] = '';

?>

<FORM method="POST">
<INPUT type="text" name="symbol" value="<?php echo
htmlspecialchars($_POST['symbol']); ?>" />
</FORM>

<?php
if ( !empty($_POST['symbol']) )
{
// loop through the sites
foreach ( $sites as $name =$url )
{
$url = sprintf($url,urlencode($_GET['symbol'])); // replaces %s with
your symbol
echo '<A HREF="'.$url.'">'.$name.'</A><BR />';
}
}
?>
Aug 14 '06 #6
Dan
I just figured that out as well. Thanks for all your help!
-Dan
BKDotCom wrote:
"typo"
I didn't change the $_GET['symbol'] from my frist post to
$_POST['symbol']
make the change and all is well

Dan wrote:
That seems to be what I want to do except that the symbol is not being
replaced. I just get an empty end of line
(http://bigcharts.marketwatch.com/int...ames.asp?symb=)


BKDotCom wrote:
reading your post again I see you don't want the "?" in your urls.
That's a result of using the "get" method with your form (the default)
here's a more complete code for your page:
>
<?php
>
$sites = array(
'marketwatch' =>
'http://bigcharts.marketwatch.com/intchart/frames/frames.asp?symb=%s',
'someothersite' ='http://www.blah.com/?ticker=%s&something=foo',
);
>
if ( !isset($_POST['symbol']) )
$_POST['symbol'] = '';
>
?>
>
<FORM method="POST">
<INPUT type="text" name="symbol" value="<?php echo
htmlspecialchars($_POST['symbol']); ?>" />
</FORM>
>
<?php
if ( !empty($_POST['symbol']) )
{
// loop through the sites
foreach ( $sites as $name =$url )
{
$url = sprintf($url,urlencode($_GET['symbol'])); // replaces %s with
your symbol
echo '<A HREF="'.$url.'">'.$name.'</A><BR />';
}
}
?>
Aug 14 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tom | last post: by
3 posts views Thread by Chris | last post: by
1 post views Thread by GlobalDeveloper | last post: by
7 posts views Thread by Mark Waser | last post: by
14 posts views Thread by Professor Yonce | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.