June 12, 201313 yr Hi Guys, I'm very new to web design. looking to put a contact form on my contact page. I've got everything together but i keep gettting a 404 error when i press the submit button. I'm wondering if it is in my Array or landing page or what..... here's the code I have... This is before the Document html code.... <?php // Set email variables $email_to = "my email goes here"; $email_subject = 'Contact From'; // Set required fields $required_fields = array('fullname','email','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email Address to continue.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'New Website Comment: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> This is in the Body: <form id="form_588312" class="appnitro" method="post" action="contact.php"> <div class="form_description"> </div> <ul > <li id="li_4" > <label class="description" for="element_4">Contact Information</label> </li> <span> <label>Full Name</label> <input id="element_4_2" name= "element_4_2" class="element text" maxlength="255" size="14" value=" <?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>"/><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?> </span> <p class="guidelines" id="guide_4"><small>Your Info will not be shared with anyone</small></p> <li id="li_2" > <label class="description" for="element_2">Email </label> <div> <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>"/><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </div> <p class="guidelines" id="guide_2"><small>Your email address will not be shared with anyone</small></p> </li> <li id="li_3" > <label class="description" for="element_3">Email </label> <div> <span style="color: rgb(15, 20, 25); font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>"/><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </span> </div> <p class="guidelines" id="guide_3"><small>Your email address will not be shared with anyone</small></p> </li> <li id="li_1" > <label class="description" for="element_1">Your Message </label> <div> <textarea id="element_1" name="element_1" class="element textarea medium"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?> </div> <p class="guidelines" id="guide_1"><small>We will not share your contact info with anyone</small></p> </li> <label class="description" for="element_7">Where did you find us </label> <div> <select name="find" id="find"> <option>Where did you find us</option> <option>Google</option> <option>Facebook</option> <option>Craigslist</option> <option>A Friend</option> <option>Other</option></select> </div> <li id="li_6" > <label class="description" for="element_6">Province </label> <div> <select class="element select medium" id="element_6" name="element_6"> <option value="" selected="selected"></option> <option value="1" >British Columbia</option> <option value="2" >Alberta</option> <option value="3" >Manitoba</option> <option value="4" >New Brunswick</option> <option value="5" >Newfoundland/labrador</option> <option value="6" >Northwest Territories</option> <option value="7" >Nova Scotia</option> <option value="8" >Nunavut</option> <option value="9" >Ontario</option> <option value="10" >Prince Edward Island</option> <option value="11" >Quebec</option> <option value="12" >Saskatchewan</option> <option value="13" >Yukon</option> </select> </div> </li> <li id="li_5" > <label class="description" for="element_5">I declare the statement to be true </label> <span> <input id="element_5_1" name="element_5_1" class="element checkbox" type="checkbox" value="1" /> <label class="choice" for="element_5_1">Yes</label> <input id="element_5_2" name="element_5_2" class="element checkbox" type="checkbox" value="1" /> <label class="choice" for="element_5_2">No</label> </span> <p class="guidelines" id="guide_5"><small>Information written here**"</small></p> </li> <li class="buttons"> <input type="hidden" name="form_id" value="588312" /> <input id="saveForm" class="button_text" type="submit" name="Submit" value="Submit" /> <?php else: ?><p>Thank You For Your Message</p> <?php endif; ?> </li> </ul> </form><?php if($form_complete === FALSE): ?> </span></div> </div> <div class="mc0203"><div class="mc020301"></div> </div> </div> </div><!-- //END MCRIGHT --> </div><!--//END MCONTENT --> </div><!--//END CONTENT --> Edited June 13, 201313 yr by RadicalDude
June 14, 201313 yr Author Hi Everyone! I really need help! I've put a contact form on my page. when i press submit, the page changes and goes to another page saying ERROR 404 page cannot be found or displayed. Can you please help me. Thank you.
June 14, 201313 yr This means that the page you are trying to redirect the user to does not exist. You should check if url you send it to exists. Maybe you made an error.
June 14, 201313 yr Author that's thing, I didn't setup a redirect code. may I send you what I have for my code, and see if you could find the error? I've watched many videos and tried everything and no luck.
June 14, 201313 yr It would probably help if you posted the code. What is the form action field set to?
June 14, 201313 yr Author Action: Post here's the code I have... This is before the Document html code.... <?php // Set email variables $email_to = "my email goes here"; $email_subject = 'Contact From'; // Set required fields $required_fields = array('fullname','email','comment'); // set error messages $error_messages = array( 'fullname' => 'Please enter a Name to proceed.', 'email' => 'Please enter a valid Email Address to continue.', 'comment' => 'Please enter your Message to continue.' ); // Set form status $form_complete = FALSE; // configure validation array $validation = array(); // check form submittal if(!empty($_POST)) { // Sanitise POST array foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value)); // Loop into required fields and make sure they match our needs foreach($required_fields as $field) { // the field has been submitted? if(!array_key_exists($field, $_POST)) array_push($validation, $field); // check there is information in the field? if($_POST[$field] == '') array_push($validation, $field); // validate the email address supplied if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field); } // basic validation result if(count($validation) == 0) { // Prepare our content string $email_content = 'New Website Comment: ' . "\n\n"; // simple email content foreach($_POST as $key => $value) { if($key != 'submit') $email_content .= $key . ': ' . $value . "\n"; } // if validation passed ok then send the email mail($email_to, $email_subject, $email_content); // Update form switch $form_complete = TRUE; } } function validate_email_address($email = FALSE) { return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE; } function remove_email_injection($field = FALSE) { return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field)); } ?> This is in the Body: <form id="form_588312" class="appnitro" method="post" action="contact.php"> <div class="form_description"> </div> <ul > <li id="li_4" > <label class="description" for="element_4">Contact Information</label> </li> <span> <label>Full Name</label> <input id="element_4_2" name= "element_4_2" class="element text" maxlength="255" size="14" value=" <?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>"/><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?> </span> <p class="guidelines" id="guide_4"><small>Your Info will not be shared with anyone</small></p> <li id="li_2" > <label class="description" for="element_2">Email </label> <div> <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>"/><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </div> <p class="guidelines" id="guide_2"><small>Your email address will not be shared with anyone</small></p> </li> <li id="li_3" > <label class="description" for="element_3">Email </label> <div> <span style="color: rgb(15, 20, 25); font-family: Arial, Helvetica, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: justify; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); display: inline !important; float: none;"> <input id="element_2" name="element_2" class="element text medium" type="text" maxlength="255" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>"/><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> </span> </div> <p class="guidelines" id="guide_3"><small>Your email address will not be shared with anyone</small></p> </li> <li id="li_1" > <label class="description" for="element_1">Your Message </label> <div> <textarea id="element_1" name="element_1" class="element textarea medium"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?> </div> <p class="guidelines" id="guide_1"><small>We will not share your contact info with anyone</small></p> </li> <label class="description" for="element_7">Where did you find us </label> <div> <select name="find" id="find"> <option>Where did you find us</option> <option>Google</option> <option>Facebook</option> <option>Craigslist</option> <option>A Friend</option> <option>Other</option></select> </div> <li id="li_6" > <label class="description" for="element_6">Province </label> <div> <select class="element select medium" id="element_6" name="element_6"> <option value="" selected="selected"></option> <option value="1" >British Columbia</option> <option value="2" >Alberta</option> <option value="3" >Manitoba</option> <option value="4" >New Brunswick</option> <option value="5" >Newfoundland/labrador</option> <option value="6" >Northwest Territories</option> <option value="7" >Nova Scotia</option> <option value="8" >Nunavut</option> <option value="9" >Ontario</option> <option value="10" >Prince Edward Island</option> <option value="11" >Quebec</option> <option value="12" >Saskatchewan</option> <option value="13" >Yukon</option> </select> </div> </li> <li id="li_5" > <label class="description" for="element_5">I declare the statement to be true </label> <span> <input id="element_5_1" name="element_5_1" class="element checkbox" type="checkbox" value="1" /> <label class="choice" for="element_5_1">Yes</label> <input id="element_5_2" name="element_5_2" class="element checkbox" type="checkbox" value="1" /> <label class="choice" for="element_5_2">No</label> </span> <p class="guidelines" id="guide_5"><small>Information written here**"</small></p> </li> <li class="buttons"> <input type="hidden" name="form_id" value="588312" /> <input id="saveForm" class="button_text" type="submit" name="Submit" value="Submit" /> <?php else: ?><p>Thank You For Your Message</p> <?php endif; ?> </li> </ul> </form><?php if($form_complete === FALSE): ?> </span></div> </div> <div class="mc0203"><div class="mc020301"></div> </div> </div> </div><!-- //END MCRIGHT --> </div><!--//END MCONTENT --> </div><!--//END CONTENT -->
June 14, 201313 yr Actually method = post, action = contact.php. Where is contact.php? Where did you get the code from?
June 14, 201313 yr Author ya I do have Method: Post Action: Contact.php I got it one of the videos on youtube. what do you mean where is the contact.php? is it all wrong?
June 14, 201313 yr When the form is submitted, its looking for the file contact.php. do you have that file? Which directory is it in?
June 14, 201313 yr Author The codes I have, are they correct? the php code for the drop downs, and the check box are they correct for validation?
June 15, 201313 yr @RadicalDude Topics merged plz don't duplicate post. sent you a message explaining more
June 15, 201313 yr Author @Moderator, just looking for help. figured i post in couple of areas hoping to get a quick reply. Do you have an answer to my question?
June 15, 201313 yr @Moderator, just looking for help. figured i post in couple of areas hoping to get a quick reply. Do you have an answer to my question? Currently no i don't its late and im tired. But for future reference Posting in multiple areas is not the way to get help. This will more often then not rub the mods the wrong way. And I don't mean to sound harsh about it but if we let one member post in multiple areas to get quick replies other members will think its ok as well. So we just got to keep the peace ya know
June 15, 201313 yr Try changing this line <form id="form_588312" class="appnitro" method="post" action="contact.php"> to <form id="form_588312" class="appnitro" method="post" action="">
June 15, 201313 yr Try changing this line <form id="form_588312" class="appnitro" method="post" action="contact.php"> to <form id="form_588312" class="appnitro" method="post" action=""> Mmm this would'nt really do any different unless of course his contact page hes trying to direct his action torward indeed isnt called contact.php but it is worth a try
June 15, 201313 yr I agree it wont do much,but it will run the the script if ,as I suspect, all his code is in the one file, and infact there is no contact.php
June 18, 201313 yr Author Hi Guys, so I checked on what you said. noticed that I had Contact capitalized. when i made the change now i get a new error message: Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log
Create an account or sign in to comment