Bootstrap modal window contact form
-
Hello!
I think this doubt if it is resolved can be very useful for everyone, it is something quite generic and reusable.
I started recently with the development of templates for WP and I got a little stuck in the next point. This is a “simple” contact form in a modal window of Bootstrap using a Shortcode.
I put the structure of the template summarized in case that helps.
header.php
==========<head>
<?php wp_head(); ?>
</head><body <?php body_class(); ?>
<?php
do_shortcode(‘[contact_form]’);
?>
<div class=?…?>
…page.php
========<?php get_header(); ?>
<!– Page Content –>
<div class=?container?>
<div class=?row?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_post_thumbnail(‘des’,array( ‘class’ => ‘img-fluid rounded’ )); ?>
<!– The content –>
<?php the_content(); ?>
<?php endwhile;?>
</div>
<!– Sidebar Widgets Column –>
<?php get_sidebar(); ?>
</div>
</div>
<!– /.container –>
<?php get_footer(); ?>footer.php
==========…
</footer><?php wp_footer(); ?>
</body>functions.php
=============function html_form_code()
{
<div class=?row justify-content-end?>
<div class=?col-auto?>
<button type=?button? id=?send? class=?btn btn-primary contact-margins?
data-toggle=?modal? data-target=?#dialogo1″>Contact</button>
</div>
</div><form action=?<?php echo ‘send.php’; ?>? method=?post?>
…
</form><!– Modal –>
<div class=?modal fade? id=?dialogo1″>
<div class=?modal-dialog modal-lg modal-dialog-centered?>
<div class=?modal-content?>
…
</div>
</div>
</div>}
function ms_contact_form()
{
ob_start();html_form_code();
return ob_get_clean();
}
add_shortcode(‘contact_form’, ‘ms_contact_form’);send.php
========Empty yet
When the button is pressed (id = ?send?) the modal window is displayed correctly, it seems that ?send.php? is called but I stay there. The flow I have built is as follows:
1) In the header I call the Shortcode that creates the modal window by clicking on the button with id = ?send?
2) In this modal window, by clicking on Send, I call the file send.php (when canceling it seems that everything works fine, the window closes without making any calls). What it does is show the header, footer and a blank page.
How do I capture the site flow in send.php, valid the form to send an email if everything is correct and show the fields that are not in the same form?
This only with PHP is very simple with WP I do not see it clearly.
It is the classic form validation -> mail delivery is correct. There are errors indicated in the same form with a warning message.
Greetings and thank you!
- The topic ‘Bootstrap modal window contact form’ is closed to new replies.