Log in

View Full Version : Pass portion of URL to web page form



jrizzo
06-27-2008, 09:08 PM
I'd like to send an email to clients that contains a URL. At the end of each URL will be a unique ID for each client. I'd like to insert some PHP code in my web page so that when the client clicks on the URL in their email message, they get taken to the web page that contains a form and the unique code portion of the URL gets passed to a field contained in the form.

I'm a total newb, so if so if someone could provide an examples of how to format the URL and what the page code would be, I'd really appreciate it. I did a search of the forum and found nothing appropriate. My apologies if I overlooked any relavent posts.

Thanks in advance for any help.

thetestingsite
06-28-2008, 12:07 AM
say that the url that is in the email is something like the following:



url.php?id=21sdfsdt213324


then you would use the following to place that in the form:



<input type="hidden" name="id" value="<?php echo $_GET['id'];?>">


Hope this helps.

jrizzo
06-30-2008, 12:37 AM
Many thanks!

I'll give it a try and let you know how I make out.

thetestingsite
06-30-2008, 12:45 AM
Just remember, if you need any help just let us know.

Jas
06-30-2008, 02:15 AM
Keep in mind that URLs can be changed by the user as well, so it's not very secure. You may need to do some extra work to validate the id.

jrizzo
06-30-2008, 03:22 AM
Thanks for the concern. In my case, it'll be OK I think. The codes relate to jobs that we're seeking feedback on. Not much of a sensitive nature involved. Even if users change the code, it'll just get emailed to us. The heads up is much appreciated though!

jrizzo
06-30-2008, 06:01 AM
Well, I'm doing something wrong because I'm getting an error when I submit the form. Here is the code for the form page and the php action associated with it. The id field appears to be the only thing that's causing errors. Any ideas?

Apologies if I included too little or too much code. Not sure what is needed at this stage of my coding education.

Also, here's a link (with sample id code) to a copy of the form online:

http://cogentcreative.com/icforms/index.php?id=JJR1234

Thanks again!

Form Page


<form id="feedback" name="feedback" method="post" action="feedback.php">
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="160" colspan="3" valign="top" class="arial_11pt_black"><p>
<label></label>
<input type="hidden" name="id" value="<?php $_GET['id'];?>">
<br />
</p>
<table width="100%" border="1" cellspacing="0" cellpadding="10">
<tr>
<td><table width="800" border="0" cellpadding="0" cellspacing="0">



Form Action


<?PHP

define('kOptional', true);
define('kMandatory', false);

define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);

define('kYes', 'yes');
define('kNo', 'no');




error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue) {
if ( get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return stripslashes($fieldValue);
}
} else {
return $fieldValue;
}
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}

function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) {
if ($limitAlpha == kYes) {
$regExp = 'A-Za-z';
}

if ($limitNumbers == kYes) {
$regExp .= '0-9';
}

if ($limitEmptySpaces == kYes) {
$regExp .= ' ';
}

if (strlen($limitExtraChars) > 0) {

$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');

$regExp .= str_replace($search, $replace, $limitExtraChars);

}

if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regExp . ']/', $value)) {
return false;
}
}

if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}

}



if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGid = DoStripSlashes( $_REQUEST['id'] );
$FTGfeedback1 = DoStripSlashes( $_REQUEST['feedback1'] );
$FTGfeedback2 = DoStripSlashes( $_REQUEST['feedback2'] );
$FTGfeedback3 = DoStripSlashes( $_REQUEST['feedback3'] );
$FTGfeedback4 = DoStripSlashes( $_REQUEST['feedback4'] );
$FTGfeedback5 = DoStripSlashes( $_REQUEST['feedback5'] );
$FTGsubmit = DoStripSlashes( $_REQUEST['submit'] );
$FTGreset = DoStripSlashes( $_REQUEST['reset'] );


# Fields Validations

$validationFailed = false;
if (!CheckString($FTGid, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['id'] = 'No ID code entered';
$validationFailed = true;
}

if (!CheckString($FTGfeedback1, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['feedback1'] = 'Feedback field 1 data required';
$validationFailed = true;
}

if (!CheckString($FTGfeedback2, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['feedback2'] = 'Feedback field 2 data required';
$validationFailed = true;
}

if (!CheckString($FTGfeedback3, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['feedback3'] = 'Feedback field 3 data required';
$validationFailed = true;
}

if (!CheckString($FTGfeedback4, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['feedback4'] = 'Feedback field 4 data required';
$validationFailed = true;
}

if (!CheckString($FTGfeedback5, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['feedback5'] = 'Feedback field 5 data required';
$validationFailed = true;
}



# Include message in error page and dump it to the browser

if ($validationFailed === true) {

$errorPage = '<html><head><title>Error</title></head><body>Errors found: <!--VALIDATIONERROR--></body></html>';

$errorPage = str_replace('<!--FIELDVALUE:id-->', $FTGid, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:feedback1-->', $FTGfeedback1, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:feedback2-->', $FTGfeedback2, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:feedback3-->', $FTGfeedback3, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:feedback4-->', $FTGfeedback4, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:feedback5-->', $FTGfeedback5, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:reset-->', $FTGreset, $errorPage);
$errorPage = str_replace('<!--ERRORMSG:id-->', $FTGErrorMessage['id'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:feedback1-->', $FTGErrorMessage['feedback1'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:feedback2-->', $FTGErrorMessage['feedback2'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:feedback3-->', $FTGErrorMessage['feedback3'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:feedback4-->', $FTGErrorMessage['feedback4'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:feedback5-->', $FTGErrorMessage['feedback5'], $errorPage);


$errorList = implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

echo $errorPage;
exit;

}
# Email to Form Owner

$emailSubject = FilterCChars("New Feedback Form");

$emailBody = "A new Feedback Form has arrived. See details below\n"
. "\n"
. "Job Code: $FTGid\n"
. "Question 1: $FTGfeedback1\n"
. "Question 2: $FTGfeedback2\n"
. "Question 3: $FTGfeedback3\n"
. "Question 4: $FTGfeedback4\n"
. "Question 5: $FTGfeedback5";
$emailTo = Form Test <john@doe.com>';

$emailFrom = FilterCChars("john@doe.com");

$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 7bit\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);


# Include message in the success page and dump it to the browser

$successPage = '<html><head><title>Success</title></head><body>Form submitted successfully. It will be reviewed soon.</body></html>';

$successPage = str_replace('<!--FIELDVALUE:id-->', $FTGid, $successPage);
$successPage = str_replace('<!--FIELDVALUE:feedback1-->', $FTGfeedback1, $successPage);
$successPage = str_replace('<!--FIELDVALUE:feedback2-->', $FTGfeedback2, $successPage);
$successPage = str_replace('<!--FIELDVALUE:feedback3-->', $FTGfeedback3, $successPage);
$successPage = str_replace('<!--FIELDVALUE:feedback4-->', $FTGfeedback4, $successPage);
$successPage = str_replace('<!--FIELDVALUE:feedback5-->', $FTGfeedback5, $successPage);
$successPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $successPage);
$successPage = str_replace('<!--FIELDVALUE:reset-->', $FTGreset, $successPage);

echo $successPage;
exit;
?>

thetestingsite
06-30-2008, 02:48 PM
The one thing that jumped out at me was the following:



<input type="hidden" name="id" value="<?php $_GET['id'];?>">


should be:



<input type="hidden" name="id" value="<?php echo $_GET['id'];?>">


Which I fixed in my previous post as well.
Hope this helps.

jrizzo
06-30-2008, 03:52 PM
That did the trick!
I was a little confused at first because I thought I had copied the code from your previous post. I thought I had slipped a cranial gear until I read that you corrected the code.

Thanks for your help. It is much appreciated!

jrizzo
06-30-2008, 07:35 PM
The code was working fine on my site/server. However, when I moved it to the client's server, it broke. I remembered that the client's ISP requires that PHP files use the extension .php4. I made this correction and everything is now fine.

Hopefully, the info regarding this requirement will help others.