12 Replies Latest reply on Jun 16, 2009 3:58 PM by Dennis48755

    How to distinguish which of two websites is linking to one insert record form.

    Dennis48755 Level 1

      Hello,

       

      First, a little history of my situation...

       

      I have created two websites displaying Old English Sheepdog pedigrees. One website is health related, requires user registration and displays special health info in the pedigree. The other is more for fun, doesn't require registration and includes pictures in the pedigree. Both are fed from the same database which is rotated between a couple folks for editing.

       

      Both wesites have a seperate copy of a form I created using ADDT's Insert Record Form wizard (with help from Albert S) to submit their dog information to be included in the database. This form includes file upload transactions for people to upload scanned pedigrees and certificates. The data from the form goes into a MySQL database. I created a Dynamic List and Detail Form that the folks editing the pedigree database can access and download the file from. The forms also have a hidden one word field indicating what website in was submitted from. And a transaction to send a thank you letter to the submitter.

       

      Both websites are beginnig to be used more and more especially the file upload fields. Since the uploaded files are stored in two seperate websites I have to manually copy them to the site pointed to by the download link in the Dynamic Detail Form.

       

      I assume files cannot be uploaded to a different websites folder (I maintain both sites hosted by the same shared linux account). So I figure the next best thing is a single form that both websites link to.

       

      Finnally, where a need help.

       

      How can I pass some kind of information about which website linked to the form. Example I would like the form to update a field in the database with website1 or website2 depending on which site linked to the form.

       

      How can I use that same website1 or website2 information with Send E-mail transactions to send different thank you E-mail letters depending on the linking website.

       

      Sorry for the long post and thanks for any assistance.

      Dennis

        • 1. Re: How to distinguish which of two websites is linking to one insert record form.
          Albert S. Level 3

          Hi Dennis,

           

          There are many ways to do this Im sure,

           

          One way would be to use $_SERVER['HTTP_REFERER'] to actually see where the user came from. Then base your form/email logic around it.


          Another way is to have different variables carried over from each site and base your logic around that.

           

          form.php?siteid=1

           

          form.php?siteid=2

           

          $_GET['siteid']

           

          If siteid == 1 do something


          if siteid == 2 do something that is different from siteid 1

           

          I'd probably go with the first one but really it's up to you.

           

           

          Reading into your questing a little further. I don't fully understand why you have to copy files from one site to the other.

           

          Message was edited by: Albert S.

          • 2. Re: How to distinguish which of two websites is linking to one insert record form.
            Dennis48755 Level 1

            Hi Albert (again)

             

            Could you please give more specific examples of your first suggestion? With my insert record form I would like to update a field named form_source with website1 or website2

             

            And how to use it to generate something to use in the email transaction.

             

            I'm not a programmer, that's why I rely heavily on ADDT's wizards.

             

            Dennis

            • 3. Re: How to distinguish which of two websites is linking to one insert record form.
              Dennis48755 Level 1

              Albert,

               

              I replied to your post, from the E-mail copy, so I missed your additional comment. The reason I have to copy files is...

               

              The submission form in Website1 has 4 file upload transactions that upload the files to a folder in website1. The files uploaded by website2's form are placed in a folder in website2.

               

              The dynamic list & detail page that I created for the folks updating the pedigree program, to retrieve information from the submissions form (MySQL DB) has a download link for each file upload field, that points only to website1.

               

              So when someone using website2's form, uploads files, I have to copy them to website1 to make them available to the dynamic list & details download links.

               

              Sorry, hard for me to explain.

              Dennis

              • 4. Re: How to distinguish which of two websites is linking to one insert record form.
                Albert S. Level 3

                Hi,

                 

                So just to show you a quick example of $_SERVER['HTTP_REFERER'], create a page ie.test1.php and in body put

                 

                <?php echo $_SERVER['HTTP_REFERER']; ?>

                 

                Then create two more pages ie. test2.php and test3.php then in each of the pages put a link to test1.php

                 

                <a href='test1.php'>Link</a>

                 

                You will see the output of $_SERVER['HTTP_REFERER'] how it basically grabs the url of the refering page.

                 

                Then you can do something like

                if ($_SERVER['HTTP_REFERER'] == 'full url/test2.php') {

                     do something here

                }


                if ($_SERVER['HTTP_REFERER'] == 'full url/test3.php') {

                     do something

                }

                 

                But I also had another thought. You said that in the database you capture if the post was made from site1 or site2.

                In the dynamic list & detail page that has the combined data you could also just change the output

                if ($row_rs['siteid'] == '1') {

                     change link here with full url to site 1

                }

                if ($row_rs['siteid'] == '2') {

                     change link here with full url to site 2

                }

                I understand your not a coder but you may have to learn some to have more control over your desired output.

                Take a look at this; The only one I have used as an example is the if statement.

                http://us2.php.net/manual/en/language.control-structures.php

                • 5. Re: How to distinguish which of two websites is linking to one insert record form.
                  Dennis48755 Level 1

                  Albert,

                   

                  Cool, but its the do something here that I don't know what I want to do with.

                   

                  Here's the form http://www.furcertain.com/forms/pedigree_submission.php. In the Insert Record Transaction is a hidden field named form_source, that field has a Default value: furcertain. On website2 there is the same form except for Default value: OESCA. This way when we look at form_source in the database we can tell which site the form came from. Here's the lines of code.

                   

                  <input type="hidden" name="form_source" id="form_source" value="<?php echo KT_escapeAttribute($row_rssubmissions['form_source']); ?>" />

                   

                  and

                   

                  $ins_submissions->addColumn("form_source", "STRING_TYPE", "POST", "form_source", "Furcertain");

                   

                  When I migrate to one form I would like the field form_source to continue to have furcertain or OESCA inserted into it.

                   

                   

                  Actually I'm anxious to learn, in fact I just bought two of David Powers books, Dreamweaver CS4..., and PHP Solutions. But I didn't know enough about what I wanted to accomplish to even try to look it up. And I haven't had time yet to go through PHP Solutions step by step. Plus I also learn well, from examples.

                   

                  Thanks

                  Dennis

                  • 6. Re: How to distinguish which of two websites is linking to one insert record form.
                    Albert S. Level 3

                    Hi,

                     

                    Lets say this is one column on the output in your dynamic list.

                     

                    <td><div class="KT_col_field"><?php echo KT_FormatForList($row_rs['field'], 20); ?></div></td>

                     

                    And inside the the field is a link like this

                     

                    http://website1.com/uploadedfiles/file.jpg

                     

                    And you also have the field that determines what site it came from. ie websiteid, OESCA

                     

                    You can do something like this

                     


                    <?php

                         $var = $row_rs['field'];

                         $varurl1 = "http://website1.com/";

                         $varurl2 = "http://website2.com/"

                         if ($row_rs['websiteid'] == 'OESCA') {

                             $output = str_replace($varurl1, $varurl2, $var);

                         } else {

                             $output = $var;

                         }

                    ?>

                    <td><div class="KT_col_field"><?php echo KT_FormatForList($output, 20); ?></div></td>

                     

                    What is happening here is prior to the output it is checking the websiteid field to determine if it needs to change the link to the other site. Then outputs it. If the websiteid it not equal to OESCA (meaning siteid 1) then it does nothing.

                     

                    I am setting some variables, then using one control structure, then if needed using a string and replace function to change the link.

                    I sent you the link to the control structures. Here is the link to the string replace function

                    http://us2.php.net/manual/en/function.str-replace.php

                     

                    Please note: I dont know how your links are structured, this is just an example of what can be done. Depending on your link structure it may need to be done another way.

                    • 7. Re: How to distinguish which of two websites is linking to one insert record form.
                      Albert S. Level 3

                      Hi,

                      On a completely differnt note, I went to your form "submit your dogs photos" and was able to upload a text file. You might want to double check what extensions are allowed.

                      • 8. Re: How to distinguish which of two websites is linking to one insert record form.
                        Dennis48755 Level 1

                        Albert,

                         

                        Thanks for the heads-up with the text file, I wondered what the garbly form entries & file was. I removed txt from the allowed file type list.

                         

                        It took me a few moments to understand your tips, then I realized it was a switch from the form to the list. Unfortunately it looks like the ADDT Dynamic List & Detail Wizard creates a special hex code to link to the file. Here is the code (from the source code of an actual listing).

                         

                                        <td><div class="KT_col_file_name">alipedigreeje.jpg</div>

                                        <a href="../includes/tng/pub/tNG_download4.php?KT_download1=4ab3bca9e3eab749549a76cbddf0e6e5 ">Download</a></td>

                         

                        Dennis

                        • 9. Re: How to distinguish which of two websites is linking to one insert record form.
                          Albert S. Level 3

                          Hi Dennis,

                           

                          Ok I had a nice weekend. YAY! So lets revisit your problem. Since the link didnt work really all you need it to send out different emails based on a single form by using an identifier to determine which website they user came from

                           

                          So basically its the same principle, take a value, check it then run code based on that value.


                          What I have done in the past that has worked for me is to just use an if statement to run diffferent email functions for different email templates.

                           

                          So first get the value from the referrer

                           

                           

                          if ($_SERVER['HTTP_REFERER'] == "http://website1.com/page.php") {

                               $checkReferer = 1;

                          } else if ($_SERVER['HTTP_REFERER'] == "http://website2.com/page.php") {

                               $checkReferer = 2;

                          } else {

                              $checkReferer = 1; //Default

                          }

                           

                          Then run one more check for the email.

                           

                          if ((isset($checkReferer)) && ($checkReferer == '1')) {

                          function Trigger_SendEmail(&$tNG) {
                            $emailObj = new tNG_Email($tNG);
                            $emailObj->setFrom("{Your_Email_Address}");
                            $emailObj->setTo("{Send_Email_Address}");
                            $emailObj->setCC("");
                            $emailObj->setBCC("");
                            $emailObj->setSubject("This Email was sent to you by: {Your_Name}");
                            //FromFile method
                            $emailObj->setContentFile("emailTemplate1.html");
                            $emailObj->setEncoding("ISO-8859-1");
                            $emailObj->setFormat("HTML/Text");
                            $emailObj->setImportance("Normal");
                            return $emailObj->Execute();
                          }

                          }

                          if ((isset($checkReferer)) && ($checkReferer == '2')) {

                          function Trigger_SendEmail(&$tNG) {
                             $emailObj = new tNG_Email($tNG);
                             $emailObj->setFrom("{Your_Email_Address}");
                             $emailObj->setTo("{Send_Email_Address}");
                             $emailObj->setCC("");
                             $emailObj->setBCC("");
                             $emailObj->setSubject("This Email was sent to you by: {Your_Name}");
                             //FromFile method
                             $emailObj->setContentFile("emailTemplate2.html");
                             $emailObj->setEncoding("ISO-8859-1");
                             $emailObj->setFormat("HTML/Text");
                             $emailObj->setImportance("Normal");
                             return $emailObj->Execute();
                          }

                          }

                           

                          There is many ways to do this, this way uses the $_SERVER['HTTP_REFERER']; You can also do it with a $_SESSION or a $_GET value.

                          • 10. Re: How to distinguish which of two websites is linking to one insert record form.
                            Dennis48755 Level 1

                            Hi Albert,

                             

                            Glad to hear you had a nice weekend, I love it when that happens, heck it's almost time for possibly another one.

                             

                            Is there a way for $_SERVER['HTTP_REFERER'] to look at just part of the URL? So it would accept http://www.website1.com/index.php, http://website1.com/index.php, http://www.website1.com/page2.php all as coming from website1? I have links to the form on a couple different pages, and the server accepts the URL with or without the www.

                             

                            Now that I finally have the value of $checkReferer (furcertain or OESCA) feeding my database form_source field, so we can continue to tell which website the form came from. I decided to try the ADDT email transaction and set the condition == "OESCA" and another email transaction with furcertain. That appears to be working fine, do you see any harm in doing it that way.

                             

                            I'm trying to use the ADDT stuff rather than writing new code, until I get a little more confident, incase for some reason I need to recreate the form. I know I need to migrate away from ADDT or find a replacement. But I'm not ready yet.

                             

                             

                            Thanks for your patience,

                            Denny

                            • 11. Re: How to distinguish which of two websites is linking to one insert record form.
                              Albert S. Level 3

                              Hi,

                              Is there a way for $_SERVER['HTTP_REFERER'] to look at just part of the URL? So it would accept http://www.website1.com/index.php, http://website1.com/index.php, http://www.website1.com/page2.php all as coming from website1? I have links to the form on a couple different pages, and the server accepts the URL with or without the www.

                              Yea, you can use parse_url to break apart the url.

                               

                              $checkReferer = $_SERVER['HTTP_REFERER'];
                              $checkReferer = parse_url($checkReferer); //More on parse_url at http://us.php.net/manual/en/function.parse-url.php

                               

                              Then use your if statement to check both spellings of the domain.

                               

                              if (($checkReferer[host] == 'website1.com') || ($checkReferer[host] == 'www.website1.com')) {  // This checks if equals one OR the other url

                                   Do Something

                              }

                               

                              Now that I finally have the value of $checkReferer (furcertain or OESCA) feeding my database form_source field, so we can continue to tell which website the form came from. I decided to try the ADDT email transaction and set the condition == "OESCA" and another email transaction with furcertain. That appears to be working fine, do you see any harm in doing it that way.

                               

                               

                              That is perfectly fine and probably better in some ways. Thats one of my problems is that sometimes when thinking about stuff I just think how to write it in normal php vs ADDT framework. When replying in these forums I need to try and rememer to stay on ADDT coding then normal php. Both get the job done but the ADDT code usually is cleaner and smaller.

                              • 12. Re: How to distinguish which of two websites is linking to one insert record form.
                                Dennis48755 Level 1

                                Albert,

                                 

                                This is working GREAT, thank you so much for your patience and expertise.

                                 

                                Dennis