Jump to content

Custom Hyperlinks


nprosper

Recommended Posts

Hey everyone, I am not a pro when it comes to PHP, I have touched a few things with it and I understand the concept to an extent. I do have a question for something I am trying to create.....

 

My goal is to create a custom link based on information entered on a form.

 

If I had the form variables as follows:

 

$name, $age, $city, $music

 

The variables contained this information for the post:

 

$name = John

$age = 25

$city = somewhere

$music = rock

 

How would it be possible to have a link displayed on their post based on the information entered. Every entry will have this link.

 

So after each time someone submits or views the posts they can see the name, age, city, music, and also a link which contains this information.

 

So logically I would want this.....

Link http://www.whateverIwant.com/width=300&height=200&level=9&style=2&Name=$name&Age=$age&city=$city&Music=$music

 

To turn into this....

http://www.whateverIwant.com/width=300&height=200&level=9&style=2&Name=John&Age=25&city=somewhere&Music=rock

 

Thanks for your help!!

 

-Nick

 

Link to comment
https://forums.phpfreaks.com/topic/109991-custom-hyperlinks/
Share on other sites

<?php
if(count($_POST) > 0 && $_POST['btnSubmit'] == "submit")
{
$url = "http://www.whateverIwant.com/";
foreach($_POST as $key=>$value)
{
	if($key != "btnSubmit")
	{
		$url .= $key . "=" . $value . "&";
	}
}
$url = substr($url, 0, -1);
?>
	<a href="<?php echo $url; ?>"><?php echo $url; ?></a>
<?php
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<input type="text" name="name" /><br />
<input type="text" name="age" /><br />
<input type="text" name="city" /><br />
<input type="text" name="music" /><br />
<input type="submit" name="btnSubmit" value="submit" /><br />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/109991-custom-hyperlinks/#findComment-564421
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.