0

What I'm trying to accomplish seems rather simple yet I do not have a strong understanding of PHP to execute it. I have a simple form with yes or no radio buttons. I'm wanting to launch a modal window upon form submission and display all of the questions that were answered yes. I'm able to launch the modal window just fine using an iframe, since I plan on having other content besides the form submission inside the modal, yet the VERY simple php script I'm using is not showing up inside the modal. Works just fine when I remove the fancybox script and keep the form action php file the same.

I'm assuming there's a conflict between the jquery and php script firing at different times but have no idea where to begin on how to fix this. Below is the code I am working with. Any help would be great and please keep in mind that I do not know how to code php.

You can see a working example on http://staging.drugrehabtest.com

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="scripts/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="scripts/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript">
    if(!jQuery.browser.mobile){
        jQuery(document).ready(function() {
            $(".fancybox").fancybox({
                'width'  : 920,
                'minHeight' : 230,
                'type'   : 'iframe',
                'padding': 20,
                'href': 'success.php',
            });
        });
    }
</script>

<form action="success.php" method="post" name="contact" id="contact">
    <input type="radio" class="checkbox" name="one" value="yes" title="Do you find yourself using drugs even when you don't want to?: Yes" />
    <label class="question">Do you find yourself using drugs even when you don't want to?</label>
    <input type="submit" name="Submit" id="submit" class="fancybox fancybox.iframe" />
</form>   

Success.php Page (minus other standard html elements)

<?php
    if ($_POST['one']=="yes") { echo "Do you find yourself using drugs even when you don't want to?"; }
?>
Manish Kumar
  • 15,269
  • 5
  • 18
  • 27
Steven Jones
  • 35
  • 1
  • 2
  • 9

4 Answers4

1

you can use

$(document).ready(function(){
        $("#"+secc+"form").submit(function(){
            var formData = new FormData($(this)[0]);
            $.ajax({
                url: '../form/',
                type: 'POST',
                data: formData,
                async: false,
                success: function (data) {
                    //history,go(-1);
                },
                cache: false,
                contentType: false,
                processData: false
            });

        return false;
        });
    });

the issue is the version jquery for the 'var formdata' only works with 1.10, and fancybox dosen't work with this version

user1710788
  • 33
  • 1
  • 6
0

In your way , the data isn't going anywhere! You have to post your data through ajax, you need a little adjustment.

 jQuery(document).ready(function() {
   $(".fancybox").fancybox({
    'width'  : 920,
    'minHeight' : 230,
    'type'   : 'iframe',
    'padding': 20,
    'href': 'success.php',
    'data': $("#contact").serializeArray(),//send all form fields
  });

In this way you can have your data in other page...

Maybe this post helps you more!

Community
  • 1
  • 1
Alireza Amiri
  • 511
  • 5
  • 24
  • Unfortunately that didn't work. I added the new 'data' field yet am still having the same problem. I took a look at the link you posted but it is all going over my head and am overwhelmed on where to start. The thing is that the data is sent fine and works perfectly when i remove the modal window. It's when I add the fancybox script that the data is no longer displaying. – Steven Jones Aug 26 '13 at 20:40
0
jQuery(document).ready(function() {
   $(".fancybox").fancybox({
    'width'  : 920,
    'minHeight' : 230,
    'type'   : 'iframe',
    'padding': 20,
    'href': 'success.php',
    'data': $("#contact").serializeArray(),//send all form fields
  });
Sagar Kodte
  • 3,723
  • 4
  • 23
  • 52
Chirag Patel
  • 559
  • 6
  • 14
  • 1
    While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – andreas Sep 30 '16 at 09:25
-1

ok, here is another way, the iframe method seems a little bit old, you can use ajax here. something like this :

First add a link in your html (in example, the last element) :

<form action="success.php" method="post" name="contact" id="contact">
    <input type="radio" class="checkbox" name="one" value="yes" title="Do you find yourself using drugs even when you don't want to?: Yes" />
    <label class="question">Do you find yourself using drugs even when you don't want to?</label>
    <input type="submit" name="Submit" id="submit" class="fancybox fancybox.iframe" /><!-- this is useless here -->
    <a id="check" data-fancybox-type="ajax" href="success.php" id="check">Result</a>
</form>  

according to this post, after that we send the data through ajax on click of link, and get the answer in the script again :

<script type="text/javascript">
jQuery(document).ready(function() {
    $('#check').on("click", function (e) {
        e.preventDefault(); // avoids calling success.php from the link
        $.ajax({
            type: "POST",
            cache: false,
            url: this.href, // success.php
            data: $("#contact").serializeArray(), // all form fields
            success: function (data) {
            // on success, post returned data in fancybox
            $.fancybox(data, {
                // fancybox API options
                fitToView: false,
                openEffect: 'none',
                closeEffect: 'none'
            }); // fancybox
            } // success
        }); // ajax
    }); // on
}); //ready
</script>

and another thing is that .browser is removed from jquery instead of that you can use Modernizr. Reference

Community
  • 1
  • 1
Alireza Amiri
  • 511
  • 5
  • 24