contact form tutorial is missing dropbox


Topic: contact form tutorial is missing dropbox

tedd asked 7 years ago

https://mdbootstrap.com/components/bootstrap-contact-form/#inputs

hello there i need add to dropbox in my contact form but i think that one is missing from your tutorial. Could you add that in the tutorial? or Could you please show us how to do it properly with one page ajax and validation?

i followed everything that you showed us in the previous tutorial but dropbox one isn't working. Maybe im doing something wrong.

Start your code here
<?php $estimate = $_POST['estimate'];header('Content-Type: application/json');if ($estimate === ''){print json_encode(array('message' => 'empty', 'code' => 0));exit();}$content="Estimate: $estimate";$recipient = "psy@nam.com";$mailheader = "From: $email \r\n";mail($recipient, $subject, $content, $mailheader) or die("Error!");print json_encode(array('message' => 'Email successfully sent!', 'code' => 1));exit();?>
Start your code here
<select class="form-control form-control-sm" name="estimate" id="estimate"><option value="estimate1">$1~$1000</option><option value="estimate2">$1000~$3000</option><option value="estimate3">$3000~$5000</option><option value="estimate4">$5000~$10000</option></select>
Start your code here
<script>function validateForm() {var x = document.getElementById('estimate').value;if (x == "") {document.getElementById('status').innerHTML = "empty";return false;}document.getElementById('status').innerHTML = "Sending...";formData = {'estimate' : $('input[name=estimate]').val(),};$.ajax({url : "mail.php",type: "POST",data : formData,success: function(data, textStatus, jqXHR){$('#status').text(data.message);if (data.code) //If mail was sent successfully, reset the form.$('#contact-form').closest('form').find("input[type=text], textarea").val("");},error: function (jqXHR, textStatus, errorThrown){$('#status').text(jqXHR);}});}</script>


                                                                    

Witold Tkaczyk commented 7 years ago

Hi, can you tell me what exactly is your problem? I see that you check if select is empty but it will never be because you don't have an option with value === "0". Please add this option to your select Choose your option

Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Open

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: General Bootstrap questions
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No