lcp2000 lcp2000 - 1 month ago 5
PHP Question

Submit a Form via a Reveal Modal

I am trying to submit a form and open a modal with the forms post data on it.

Modal works fine but the form post is not passed through.

I have tried jquery/ajax but no luck.

<form id="frmTractors" method="post" action='process.php'>
<select id="tractor" name="tractor_number">
<options...>
</select>

<input type="submit" value="Submit" data-reveal-id="myModal" data-reveal-ajax="process.php" />
</form>

<!-- ### MODAL ### -->
<div id="myModal" class="reveal-modal" data-reveal></div>

Answer

I am running something similar on a site:

HTML

<input type="hidden" id="processURL" value="process.php">
    <select id="tractor" name="tractor_number">
       <options...>
    </select>

JQUERY

$(function() {  
    $( "#tractor" ).change(function(){
        var url = $('#processURL').val();
        var tractor_number = $(this).val();                 
        var postit = $.post( url, {tractor_number:tractor_number});     
        postit.done(function( data ) {

        $('#myModal').foundation('reveal', 'open');

        });     
    }); 
}); 

You don't need a form, just a hidden input to hold your process file URL.

Comments