Results 1 to 10 of 10

Thread: Pass portion of URL to web page form

  1. #1
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Pass portion of URL to web page form

    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.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    say that the url that is in the email is something like the following:

    Code:
    url.php?id=21sdfsdt213324
    then you would use the following to place that in the form:

    Code:
    <input type="hidden" name="id" value="<?php echo $_GET['id'];?>">
    Hope this helps.
    Last edited by thetestingsite; 06-30-2008 at 02:48 PM.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    jrizzo (06-30-2008)

  4. #3
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    Many thanks!

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

  5. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Just remember, if you need any help just let us know.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #5
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    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.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  7. The Following User Says Thank You to Jas For This Useful Post:

    jrizzo (06-30-2008)

  8. #6
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default

    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!

  9. #7
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default 1st Attempt Failed

    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
    Code:
    <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
    Code:
    <?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;
    ?>
    Last edited by jrizzo; 06-30-2008 at 06:12 AM.

  10. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The one thing that jumped out at me was the following:

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

    Code:
    <input type="hidden" name="id" value="<?php echo $_GET['id'];?>">
    Which I fixed in my previous post as well.
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  11. #9
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Thumbs up Success!

    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!

  12. #10
    Join Date
    Jun 2008
    Posts
    7
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Follow-up

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •