I understand how to pass form data from one form to the other when using an action in the form tag, but I'm not using this, because I want to perform some PHP on the first page with the initial form.
Once this code has been executed, then I'd like to redirect to the next form, and pass through the values entered. I managed to do this before I added the PHP code by using $_REQUEST
on the second form, and by setting the action of the first form, to be the second form page.
Can this still be done when the action is removed from the first form?
Action when submit button is clicked
// Send email if Book Enquiry form is submitted
if(isset($_POST['bookEnquiry'])) {
$to = 'local@localhost.local';
$subject = 'Enquiry Interest from BellaVou';
$firstname = isset($_POST['firstname']) ? $_POST['firstname'] : '';
$surname = isset($_POST['surname']) ? $_POST['surname'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$message = $firstname.' '.$surname.' ('.$email.') has just submitted the initial enquiry form.';
$headers = 'From: local@localhost.local' . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
wp_safe_redirect('/contact-us/enquiry-form');
}
Form on first page
<form class="form-horizontal" method="post">
<div class="form-group">
<label for="firstname" class="col-sm-3 control-label">First Name</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="firstname" id="firstname" required />
</div>
</div>
<div class="form-group">
<label for="surname" class="col-sm-3 control-label">Surname</label>
<div class="col-sm-6">
<input type="text" class="form-control" name="surname" id="surname" />
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Email</label>
<div class="col-sm-6">
<input type="email" class="form-control" name="email" id="email" required />
</div>
</div>
<div class="form-group">
<button class="btn btn-primary" name="bookEnquiry">Continue</button>
</div>
</form>
Aucun commentaire:
Enregistrer un commentaire