Link to home
Start Free TrialLog in
Avatar of James Murrell
James MurrellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

parse url to form?

hi i would like to email a url to people which would include a parameter that when there go to the webpage it would populate the field

example url (this is a page which is live :-)

http://f1cs97jjm3.ddns.net/profile/join_league.php?[League_owner]=Webroster  
example webpage

<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">

input,
textarea {
  border-radius: 0 !important;
  outline: none !important;
  -webkit-appearance: none;
}
</style>
</head>

<body>


<form id="j" action="" method="post">
<input id='League_owne' type='text' value='' >
<input name="Submit1" type="submit" value="submit" /></form>


</body>

</html>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Not sure I understand the question.  Can you use an example that shows how to email a URL with a link that is recognized by the server?

Also, do you really need a DOCTYPE declaration for Transitional?  I think I might want to get rid of that.  Just a thought.
Avatar of James Murrell

ASKER

the link is what i put in question:
http://f1cs97jjm3.ddns.net/profile/join_league.php?[League_owner]=Webroster

i agree about html i just quickly built a page... needed a form
I think what you need is to read the first key in the query string. Please use the Request.QueryString in your page load event as follows:
var n = Request.QueryString;
// See if any query string exists
if (n.HasKeys())
{
    // Get first key and value
    string key = n.GetKey(0);
    string value = n.Get(0);
	//Populate your field or whatever logic you need from values above, for example
	League_owne.Text = key; //assuming League_owne is a server textbox. 
}

Open in new window

where League_owne is a server textbox defined as:
<asp:TextBox ID="League_owne" runat="server" Height="35" />

Open in new window

OK, let's take this one step at a time.  First you have to be able to find the URL request variables.

See https://iconoun.com/demo/temp_cs97jjim3.php

See https://iconoun.com/demo/temp_cs97jjim3.php?League_owner=Webroster

The link below does not work, probably because of the square brackets.  They have special meanings in URLs and PHP code, so it's wise to omit them from the request variables unless you know exactly why you're putting them into the request.
https://iconoun.com/demo/temp_cs97jjim3.php?[League_owner]=Webroster

Here is the script that uses the request variables and displays them in the browser viewport.
<?php // demp/temp_cs97jjim3.php
/**
 * https://www.experts-exchange.com/questions/29005124/parse-url-to-form.html
 */
error_reporting(E_ALL);


// FIND THE URL REQUEST VARS
var_dump($_GET);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
wow this is great stuff: great explanation: thank you... from this i can hopefully learn and build once again thanks
Glad things are working and thanks for your kind words!  Here is the request_reflector.php script.  I've found it useful in a lot of situations!
<?php // demo/request_reflector.php
/**
 * Bounce the request vars back
 */
error_reporting(E_ALL);
date_default_timezone_set('America/Chicago');

// START A BUFFER TO CAPTURE THE BROWSER OUTPUT
ob_start();

// USE PREFORMATTING TO MAKE THE OUTPUT EASY TO READ
echo '<pre>';

// SHOW THE COOKIE(S)
echo '$_COOKIE: ';
var_dump($_COOKIE);
echo PHP_EOL;

// SHOW THE GET REQUEST
echo '$_GET: ';
var_dump($_GET);
echo PHP_EOL;

// SHOW WHAT WAS RECEIVED IN POST
echo '$_POST: ';
var_dump($_POST);
echo PHP_EOL;

// SHOW WHAT WAS RECEIVED IN FILES
echo '$_FILES: ';
var_dump($_FILES);
echo PHP_EOL;

// CAPTURE THE BUFFER
$request_data = ob_get_clean();

// SAY THANK YOU
$refer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '(empty referrer)';
echo 'REQUEST REFLECTED FROM ' . $refer . ' AT ' . date('c');
echo PHP_EOL;
echo $request_data;

Open in new window