Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing form from iframe to parent with conditions
    primarykey
    data
    text
    <p>I recently asked a similar question <a href="https://stackoverflow.com/questions/9672149/close-colorbox-iframe-after-form-submit-and-then-redirect-parent-page">Close Colorbox iframe after form submit and then redirect parent page</a> but have since changed direction a little so I thought best to create a new post.</p> <p>I have an add to cart form inside of an iframe(both my parent and iframe reside on the same server/directory). On submit I would like to pass the form to a script on the parent page. the script will close the iframe(colorbox) window and submit the form, but there is one exception; I have two versions of my site, one for standard browsers which uses an iframe to display the the product, and a mobile site which directly opens the product page and works fine as-is. Both use the same database where the info is stored, which means the forms are always the same, So I need a conditional, something along the lines of <strong>if this page is in an iframe (pass form to script on parent for submission) else (submit form as-is)</strong>. I have found this snippet here on stackoverflow that I believe should work for the conditional:</p> <pre><code>if (top === self) { not in a frame } else { in a frame } </code></pre> <p>I have three different forms, each is on a separate product page:</p> <p>The most basic:</p> <pre><code>&lt;form name="add_cart" action="index.php?action=add" method="post" enctype="multipart/form-data"&gt; &lt;input type="hidden" name="quantity" value="1" /&gt; &lt;input type="hidden" name="products_id" value="1" /&gt; &lt;input type="hidden" name="id[1]" value="1" id="att-1-1" /&gt; &lt;input type="hidden" name="id[2]" value="2" id="att-2-2" /&gt; &lt;input class="cssButton button" type="submit" value="Add Product"/&gt; &lt;/form&gt; </code></pre> <p>Then one with multiple checkbox selections:</p> <pre><code>&lt;form enctype="multipart/form-data" method="post" action="index.php?action=add" name="cart_quantity"&gt; &lt;input type="hidden" value="1" name="quantity"&gt; &lt;input type="hidden" value="3" name="products_id"&gt; &lt;input id="option-8-1" type="checkbox" value="1" name="id[8][1]"&gt; &lt;input id="option-8-2" type="checkbox" value="2" name="id[8][2]"&gt; &lt;input id="option-8-3" type="checkbox" value="3" name="id[8][3]"&gt; &lt;input id="option-8-4" type="checkbox" value="4" name="id[8][4]"&gt; &lt;input class="cssButton button" type="submit" value="Add Selected Items" &gt; &lt;/form&gt; </code></pre> <p>And a third with a drop down selection for a single option:</p> <pre><code>&lt;form enctype="multipart/form-data" method="post" action="index.php?action=add" name="cart_quantity"&gt; &lt;input type="hidden" name="quantity" value="1" /&gt; &lt;input type="hidden" name="products_id" value="3" /&gt; &lt;input type="hidden" name="id[6]" value="9" id="att-6-9" /&gt; &lt;select name="id-7" id="options"&gt; &lt;option value="1"&gt;option 1&lt;/option&gt; &lt;option value="2"&gt;option 2&lt;/option&gt; &lt;option value="3"&gt;option 3&lt;/option&gt; &lt;option value="4"&gt;option 4&lt;/option&gt; &lt;/select&gt; </code></pre> <p> </p> <p>I'm looking for any help or guidance into getting this to work. While I have a better grip on javascript, Jquery would be fine, Anything is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload