How to add additional field in Contact form?
If you need to add additional field (phone field for example) to your Contact form you need to make next steps:
Open contacts.html and find form markup (line 213) then add markup for additional input after some existing field.
<div class="field"> <label for="email">Email:</label> <input type="email" name="email" id="email"> </div>
- Then you need to open sendMail.php and define new variable called $phone after existing variables (line 7)
$phone = $_POST['phone'];
Then replace this code on line 34
$mail->Body = $comments;to this one
$mail->Body = "Phone ".$phone."\r\n"; $mail->Body .= $comments."\r\n";
As you can see you just concatenate new field (Phone) with existing Comments.
And the last thing you need to open js/jquery.form.js and define variable by inserting code after 15 line
var phone = $('input#phone').val();
and add this variable in ajax result. You should see next code:
data: 'name=' + name + '&email=' + email + '&subject=' + subject + '&phone=' + phone + '&comments=' + comments,