How do I get the values of Advanced Custom Fields and join it together in my email form when user submit it?
I am trying to make a ticket booking/reservation but with selection from ACF values.
- I have a form that shows multiple ticket entries from ACF
- The user can select multiple tickets by increasing the quantity on the specific ticket.
- The selected tickets (Ticket Name, Price and Quantity) together with his information will be sent by email.
Please image attached: enter image description here
To increase the quantity of the ticket to purchase, i have included an input form type number in the ticket loop.
The code below is working except on the field that is generated from Advanced Custom Form.
Mailer:
if (isset($_POST['submit'])) {
$to = "myemail@gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$ticket = $_POST[get_sub_field('ticket_type')];
$subject = "Form submission";
$message = $first_name ."Ticket" . $ticket . "\n" . $_POST['message'];
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
Form:
<form action="" method="post">
<table>
<thead>
<tr>
<th scope="col">Buy Ticket</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
<?php
if (have_rows('tickets')):
while (have_rows('tickets')) : the_row();
?>
<tr><td class="font-bold"> <i class="fas fa-ticket-alt"></i><?php the_sub_field('ticket_type'); ?></td>
</td>
</tr>
<tr><td><small><i><?php the_sub_field('ticket_description'); ?></i></small></td>
<td>Ticket Quantity:<input name="<?php the_sub_field('ticket_type'); ?>" class="form-control-sm m-r-10" type="number" name="quantity" min="1" max="5">
</td>
</tr>
<?php
endwhile;
else :
endif;
?>
</tbody>
</table>
First Name: <input type="text" name="first_name">
Email: <input type="text" name="email">
Message <textarea rows="5" name="message" cols="30"></textarea>
<input type="submit" name="submit" value="Submit">
</form>
The ticket is in a "Repeater" so it will generate more depending on the entries.
How can I include the user-selected ticket (name and price) with the its quantity on the email?
Thank you!