This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Getting URL with Hash Tags


  1. toddbuchanan
    Member

    I am embeding my form with the iframe tags into a page on smugmug.com...a photo sharing site...and have been trying to get the referring URL included in my form so that when someone submits it...it will link back to the specific photo on that page, rather than just the gallery page that I am getting at the moment...

    I have been able to get the HTTP_Referr URL into one of my fields but I am working with a form (and site) that uses Hash (or Anchor) tags at the end. I know that PHP is server side and the hash tags get added on the client side after the page has been loaded, so my HTTP_Reffer URL does not contain anything that comes after the hash tag...

    I know that the javascript location.href or window.location.href do a great job of getting that info, but obviously, javascript and PHP don't play well together...

    I thought I saw a php HTTP_Hash command but at this point (after three long days of trying to find an answer) I am stumped...I'm no java/PHP expert, but know just enough to be dangerous...

    The site that I am working with (smugmug.com...a photo sharing website for my business) I thin is using AJAX...is there another solution for getting AJAX to insert something into one of my MachForm fields?

    Here is my form embeded in one of the pages: http://aacr3.smugmug.com/AACR-2010-Annual-Meeting/AACR-2010-Annual-Meeting/11756856_8qYrj#830059095_j3KUA

    Thanks in advance!

    Todd

    Posted 14 years ago #
  2. yuniar

    Hmm.. I think you can use a simple Javascript for this, without Ajax.

    For your form above (form id = 6 and the http referrer field is having id = element_9)
    Edit your "includes/view-functions.php" file.

    Search line 1841:

    <form id="form_{$form->id}" class="appnitro" {$form_enc_type} method="post" action="#main_body">

    change it to become:

    <form id="form_{$form->id}" name="form_{$form->id}" class="appnitro" {$form_enc_type} method="post" action="#main_body">

    Then around line 1855, before the closing body tags, modify the code to be like this:

    <img id="bottom" src="images/bottom.png" alt="" />
    
    <script>
    document.form_6.element_9.value = window.location.href;
    </script>
    
    </body>

    as you can see, between the img and body tag, we insert the javascript which assign the window.location.href into your http referrer field.


    MachForm Founder

    Posted 14 years ago #
  3. toddbuchanan
    Member

    Fantastic! Thanks yuniar!

    I was hoping that if I embedded the form with the iFrame that it would pick up the URL with the hash tags, but since the hash tags are loaded client side (after Ajax creates the page) the javascript is only reading the URL where the form is first created.

    I wish I know more javascript (and I will try to find an answer to my own question) but I think what I need to do is either:

    A: have some sort of refresh take place so that the javascript will read the URL and the current hash tags once the page has loaded.

    Or

    B: Create some javascript submit action (maybe associated with your submit button?) so that it will grab the current URL and hash tag that the form is residing on (or embedded in) before submitting it.

    Thanks again...great product...

    Posted 14 years ago #
  4. yuniar

    Ah... right. I think "window.location.href" won't work when you embed the form within iframe.

    I see that you have implemented the code.
    Can you try one more time for me?

    Try to replace:

    document.form_6.element_9.value = window.location.href;

    with this one:

    document.form_6.element_9.value = top.location;

    I think this one should get the parent URL instead of the form URL.


    MachForm Founder

    Posted 14 years ago #
  5. toddbuchanan
    Member

    Yuniar...thanks again...I didn't realize it might add one more problem by putting it in an iFrame...I tried it and it doesn't get the current URL (it still gets the source: i.e. http://www.toddbuchanan.com/machform/embed.php?id=6)...

    I did a quick read and found that the frames cause one problem:

    Didn't know if this might be an answer to the problem: http://www.trans4mind.com/personal_development/JavaScript/jsFrames.htm

    Again, thank you so much...let me know if launching in a pop up window would work any better (if there was a way to pass a default value to form_6.element_9...)...

    Posted 14 years ago #
  6. yuniar

    Hmm.. I think I found the problem. The code I posted above only work if the iframe content and the parent page are both coming from the same domain.

    In your case, they are different, hence top.location object won't work at all. This is security restriction within browsers.

    More detailed explanation here:
    http://stackoverflow.com/questions/1113902/what-exactly-can-an-iframe-do-with-the-top-location-object-cross-domain

    I can't find any workaround yet :( Sorry


    MachForm Founder

    Posted 14 years ago #

RSS feed for this topic

Reply