Redisplay modal after errors detected

I have a modal with an html form within it. The modal includes a span defined like this:

<span> <?php echo $error; ?></span>

When the modal is first displayed, the $error variable doesn't exist yet so the span is empty. The php script which executes when the Submit button is clicked carries out various validation checks and if any errors are found, it sets the $error variable.

I can't figure out how to force the modal to be re-displayed so the errors show up. I know this isn't strictly a BSS question but hoping someone out there may have a solution.

Thanks, Pete

I don't know PHP and I'm not that good at script writing anyways. But my suggestion would be that you find a way for the script to halt the submit until after the the server responds with success or error. If it's success then close the modal if error display the error.

I know in jQuery you can do something like

$("form").on("submit",function(e){ 
    e.preventDefault();
    // do some ajax form submit stuff 
});

Take a look here http://stackoverflow.com/questions/1960240/jquery-ajax-submit-form

Saj

Thanks Saj. I had come across some solutions based on Ajax but was hoping I wouldn't have to get into that. Another solution I found was for the PHP script to echo a javascript back to the form which would execute the Bootstrap js commands to display the modal. That would be a much simpler way to go but so far I haven't been able to get it to work. Pete