Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //How do I submit the data of a form to an iframe in Fancybox?
- Option 1: Show just the results (as HTML) in Fancybox:
- $("#my-form").submit(function() {
- $form = $(this);
- $.ajax({
- url: $form.attr("action"),
- type: 'POST',
- dataType: 'html',
- data: $form.serialize(),
- success: function(data, textStatus, xhr) {
- $.fancybox({
- 'title': "form submission",
- 'content': data
- });
- },
- error: function(xhr, textStatus, errorThrown) {
- alert("An error occurred.");
- }
- });
- return false;
- });
- Option 2: Change to a GET request and use a Fancybox Iframe:
- $(function() {
- $("#my-form").submit(function() {
- $form = $(this);
- $.fancybox({
- 'title': "form submission",
- 'href': $form.attr("action") + "?" + $form.serialize(),
- 'type': 'iframe'
- });
- return false;
- });
- });
- Option 3: Forget FancyBox and do this thing yourself
- <script>
- $(function() {
- $("#my-form").submit(function() {
- $form = $(this);
- $iframe = $("#form-submission");
- $window = $(window);
- $iframe.css({
- height: 500,
- width: 500,
- position: "absolute",
- left: ($window.width() / 2) - 250,
- top: ($window.height() / 2) - 250
- });
- $iframe.fadeIn();
- });
- });
- </script>
- <form action="test.php" method="post" target="form-submission" id="my-form">
- <input name="q" value="myvalue">
- <p><input type="submit" value="submit"></p>
- </form>
- <iframe src="#" name="form-submission" id="form-submission" style="display: none;
Advertisement
Add Comment
Please, Sign In to add comment