Jump to content

jack123

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by jack123

  1. hi guys, I create a php form field to be sent to my email when submitted. However, it failed to send my phone field when I fill it out. Im not sure what is the issue, can you guys gives some advice? <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $phone = $_POST['phone']; $human = $_POST['human']; $email_to = "hello@something.com"; $email_subject = "web customer"; $formcontent = " From: $name \n email: $email \n Phone: $phone \n Message: $message"; if (($name=="") || (strlen($name)< 2)){ echo "Please fill in your name...(need to be more than 2 character)"; } else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ echo "E-mail address invalid!!"; } else if (($message== "") || (strlen($message)>250)){ echo "Message cannot be empty or greater than 250 characters..."; } else if ($human !='2'){ echo 'Sorry, your maths is wrong, please try again '; exit(); } else{ //header("location: ../thanks.html"); echo 'E-mail sent!! I will try my best to reply within 24 hours '; $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $formcontent, $headers); } ?> <html> <form action="mail.php" id="contact_form" method="POST" onsubmit="formReset();"> <ul> <li><input type="text" name="name" placeholder="Name" class="input_item field_name" id="name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'" required value="" /></li> <li><input type="email" name="email" placeholder="Email" class="input_item field_email" id="email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email'" required value="" /></li> <li><input type="tel" name="phone" placeholder="Phone (optional)" class="input_item field_phone" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Phone'" value=""/></li> <li><textarea type="message" name="message" placeholder="Message" class="input_item field_message" id="message" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Message'" required value=""/></textarea></li> <li><input type="text" name="human" placeholder="What is 1+1? (Anti-spam)" class="input_item field_spam" id="human" onfocus="this.placeholder = ''" onblur="this.placeholder = 'What is 1+1? (Anti-spam)'" required value=""/></li> <li class="full"><button input type="image" value="" name="submit" id="button" onClick="javascript:ajax_post();" /></button></li> </ul> </form> </html>
  2. Thanks Ben, I figure it out the issues: 1) When I tell php to echo those condition, I didn't give instruction to prevent form submission and contact with server. Basically, I should have use some js method to stop form from submiting before validate was verified... 2) I didn't split each post variable and give its separate validation and condition 3) I am a designer first and developer second...so I sometimes code basic on how I feel not on reason or logic. ( I had logic error). <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $phone = $_POST['phone']; $human = $_POST['human']; $email_to = "hello@somewhere.com"; $email_subject = "web customer"; $formcontent = " From: $name \n email: $email \n Phone: $phone \n Message: $message"; if (($name=="") || (strlen($name)< 2)){ echo "Please fill in your name..."; } else if (!filter_var($email, FILTER_VALIDATE_EMAIL)){ echo "E-mail address invalid!!"; } else if (($message=="") || (strlen($message) >250)){ echo "Message( must be less than 250 characters)"; } else if ($human !='2'){ echo 'Sorry, your math is wrong, please try again '; exit(); } else{ //header("location: ../thanks.html"); echo 'E-mail sent!! I will try my best to reply within 24 hours '; $headers = 'From: '.$email."\r\n". 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $formcontent, $headers); } ?> If you see any security issue that I need to improve on, please let me know. Thanks Ben for your contribution to the web community.
  3. Hiii guys..I create this form validate through php, but its update using ajax to display the condition messages. However, when it gets down to the last condition statement in php, the form submitted without even displaying the error... It suppose to display the condition for "spam field"..or "human". Thank you I would really appreciate it if someone can help me out. http://geohound.net16.net/test/index.html <?php $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $human = $_POST['human']; if ($name=="" || $email=="" || $message==""){ echo "please filled out all required field!"; } elseif ($human!=="2"){ echo "Your spam is wrong!"; } else{ echo "Congrats!"; } ?> this is ajax function ajax_post(){ // Create our XMLHttpRequest object var hr = new XMLHttpRequest(); // Create some variables we need to send to our PHP file var url = "my_parse_file.php"; var fn = document.getElementById("name").value; var ln = document.getElementById("message").value; var em = document.getElementById("email").value; var message = document.getElementById("message").value; var human = document.getElementById("human").value; var vars = "name="+fn+"&message="+ln+"&email="+em+"&message="+message+"&human="+human; hr.open("POST", url, true); // Set content type header information for sending url encoded variables in the request hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); // Access the onreadystatechange event for the XMLHttpRequest object hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200) { var return_data = hr.responseText; document.getElementById("status").innerHTML = return_data; } } // Send the data to PHP now... and wait for response to update the status div hr.send(vars); // Actually execute the request document.getElementById("status").innerHTML = "processing..."; }
×
×
  • Create New...