WilliamS9659 Posted July 15, 2015 Share Posted July 15, 2015 I am really new to creating websites I am trying to create one for a friend. I attached zip file of site. I used generic photos I will replace soon. My issue is in the Contact Form when I hit submit button it does not work. I wanted it to redirect to contact_me.php which is located in mail file. The structure I am using is for a free form I downloaded. Thanks everyone for all your help in advance. I just cannot make the connection occur between the the button and php to work properly ugh!! I also would really appreciate any directions and comments. The blog section is not done yet. Sweetshoppe.zip Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/ Share on other sites More sharing options...
scootstah Posted July 15, 2015 Share Posted July 15, 2015 Please post the relevant portions of code here in code tags. Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516381 Share on other sites More sharing options...
WilliamS9659 Posted July 15, 2015 Author Share Posted July 15, 2015 I hope this is what you meant by relevant code. Thanks Everyone For all your help and assistance. Contact Form Code Below <div class="container"> <div class="row"> <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1"> <p>Want to get in touch with me? Fill out the form below to send me a message and I will try to get back to you within 24 hours!</p> <!-- Contact Form - Enter your email address on line 19 of the mail/contact_me.php file to make this form work. --> <!-- WARNING: Some web hosts do not allow emails to be sent through forms to common mail hosts like Gmail or Yahoo. It's recommended that you use a private domain email address! --> <!-- NOTE: To use the contact form, your site must be on a live web host with PHP! The form will not work locally! --> <form name="sentMessage" id="contactForm" novalidate> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Name</label> <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Email Address</label> <input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Phone Number</label> <input type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label>Message</label> <textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea> <p class="help-block text-danger"></p> </div> </div> <br> <div id="success"></div> <div class="row"> <div class="form-group col-xs-12"> <a href="index.html"> <button type="submit" class="btn btn-default">Send</button> </a> </div> </div> </form> </div> </div> </div> Contact_Me.PHP for form Below (I removed Email Address) <?php // Check for empty fields if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) { echo "No arguments Provided!"; return false; } $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $message = $_POST['message']; // Create the email and send the message $to = 'MyEmailGoesHere.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. $email_subject = "Website Contact Form: $name"; $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; $headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); return true; ?> Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516424 Share on other sites More sharing options...
scootstah Posted July 15, 2015 Share Posted July 15, 2015 (edited) You didn't tell your form to use POST. <form method="POST" name="sentMessage" id="contactForm" novalidate>Unless your form HTML is on the same script (Contact_Me.PHP), you also need to put an action. <form method="POST" action="Contact_Me.php" name="sentMessage" id="contactForm" novalidate>Also, saying return false; in the middle of a script does nothing. Everything underneath that is still going to execute. Edited July 15, 2015 by scootstah Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516426 Share on other sites More sharing options...
WilliamS9659 Posted July 15, 2015 Author Share Posted July 15, 2015 Where would I place the action you mentioned in my script? <form method="POST" action="Contact_Me.php" name="sentMessage" id="contactForm" novalidate> Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516463 Share on other sites More sharing options...
cyberRobot Posted July 15, 2015 Share Posted July 15, 2015 The extra attributes would go in the following <form> tag: <form name="sentMessage" id="contactForm" novalidate> Note that the attribute order doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516470 Share on other sites More sharing options...
cyberRobot Posted July 15, 2015 Share Posted July 15, 2015 Thinking about the problem some more, I have a feeling that there is some JavaScript attached to the form that's adding the action and method attributes for you. Did you make any changes to the open <form> tag after downloading script? When you submit the form, where does it go? Does it go back to the page where your form code is hosted? Or does it go to contact_me.php in the mail folder? Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516478 Share on other sites More sharing options...
WilliamS9659 Posted July 15, 2015 Author Share Posted July 15, 2015 I am not really sure. I thought once I hit Submit it would trigger php and once everything is satisfied in the PHP code it would email me it. I did attach website to first post. Its not very big. Thank you so much for all your help Quote Link to comment https://forums.phpfreaks.com/topic/297300-help-with-contact-php/#findComment-1516505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.