0

Is there a way to submit a form to Facebox? As it is right now you need to use an anchor tag to invoke the facebox method but I need to submit a form and send the data to the php handler and show it in facebox.

So if I'm on order.html and then submit the add to cart button and the cart is on index.php?action=add (form action) which excepts some post variables. Is it possible to show the cart but not take me to index.php?

  • 1
    Do you mean, the facebox remain open and the content inside the facebox changes after the submit? – karim79 Jun 29 '09 at 11:25
  • NO & YES. After I submit the form I want facebox to pop open and show the contents of the cart, but I also want to click a button inside facebox and the action changes from just index.php (showing the cart contents) to say index.php?action=checkout so the content changes but the php file is still the same. In short, I have a simple freshbooks cart a friend wrote that I'm trying to modify to use facebox because some of the pages are way to small to load all by themselves. –  Jun 29 '09 at 13:06

2 Answers2

1

Try this...

//open script tag

jQuery(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
})

// close script tag


//check if form is submitted

//open script tag

 jQuery.facebox({ ajax: 'filename_to_open_in_fb.php' });

// close script tag

hope this was helpful....

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Sonia
  • 21
  • 1
0

This little tutorial should help accomplish what you are trying to do: http://ronaldarichardson.com/2011/03/17/how-to-submit-post-php-data-to-facebox/

Here is the code excerpt from it as well.

<script type="text/javascript">
function decrypt_form() {       
    $.facebox(function() {
        $.ajax({
            data: { "id" : $("#id").val() },
            error: function() {
                $.facebox("There was an error decrypting the form submission");
            },
            success: function(data) {
                $.facebox(data);
            },
            type: "post",
            url: "decryptAndShow.php?form='.$form.'"
        });     
    });  
}

Ron
  • 1
  • 1