So my issue is as follows.
I'm learning wordpress and creating a custom theme. The idea was to create a dynamic modal which contains a form, that i can reuse in different places. I created the modal in the service-modal.php file and use it on the front-page.php.
My submit function is not triggering at all, so whatever I add to the submit doesn't show up, not even simple echo's.
I assume that my form action is wrong, but I can't find a similar problem/solution to look into.
Here is my service-modal.php
<?php
//Service modal
//function service_modal($args){
if(isset($_POST['submitted'])) {
$my_post = array(
'post_title' => 'Test Title',
'post_status' => 'publish',
'post_type' => 'inquiries'
);
$newpost = wp_insert_post($my_post);
if (!is_wp_error($newpost)) {
echo 'success';
} else {
echo 'error';
}
}
//$post = $args['service'];
$orgTitle = get_field('title');
$title = str_replace(' ', '', $orgTitle);
?>
<div class="service-modal <?php echo strtolower($title)?> ">
<form id="serviceInquiry" action="<?php get_permalink(); ?>" method="post">
<div class="service-modal-header">
<h4>You've selected the <span name="spackage"><?php echo get_field('title');?></span> package</h4>
<span class="close-modal">Close<span>
</div>
<div class="service-modal-content">
<div class="service-modal-content-details">
<h5>Selected package includes:</h5>
<ul class="service-list">
<?php
for ($x = 1; $x < 7; $x++){
if(get_field('item_'.$x) != ""){
?>
<li><p><?php echo get_field('item_'.$x);?></p></li>
<?php
}
}
?>
</ul>
<div class="price-group">
<span>$<span class="price" name="sprice"><?php echo get_field('price');?></span>/<span class="price-value"><?php echo get_field('price_value');?></span></span>
</div>
</div>
<div class="service-modal-content-form">
<h5>Leave us your details:</h5>
<input type="text" placeholder="Name" name="username">
<input type="text" placeholder="Email" name="semail">
<textarea placeholder="Message" name="smessage"></textarea>
</div>
</div>
<div class="service-modal-footer">
<div class="buttons">
<button type="button" class="cancel-btn">Cancel</button>
<button type="submit" class="send-btn">Send inquiry</button>
</div>
</div>
</form>
</div>
<?php
?>
And I use this modal part on the front-page.php just like this:
include( locate_template( 'service-modal.php', false, false ) );
As I mentioned, I somehow assume my form action is wrong, but don't rally understand why, nor can I find the solution.
If anyone knows the solution I would be really grateful if I get the "why" also, because I really would like to understand. I know that I can probably handle this form submit with ajax, but also would like to get it done this way before.