queketth Posted June 6, 2011 Share Posted June 6, 2011 Hi there I am attempting to make a javascript form echo for a php form to replace the echo section of my script (which currently appears on a separate page with just plain text) I basically hope that i can have a little popout window that says "thankyou for contacting us!" or "please fill in the form with all the required details" etc replacing the current php echo... Very unsure of how i would go about this and any help would be greatly appreciated... The code below is the current PHP <?php $name = $_POST['Name']; $email = $_POST['Email']; $telephone = $_POST['Telephone']; $type = $_POST['Type']; $message = $_POST['Message']; $formcontent=" From: $name \n Type: $type \n Message: $message \n Telephone: $telephone"; $recipient = "enquiries@hqandco.com"; $subject = "Contact Form"; $mailheader = "From: $email \r\n"; if($name =="" || $email =="" || $type =="" ||$message =="" ){ echo"Fill the fields"; } else{ mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/ Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 not even sure what you are asking to be honest Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226078 Share on other sites More sharing options...
queketth Posted June 6, 2011 Author Share Posted June 6, 2011 I have attempted to clarify is this any better ? Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226087 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 You shouldn't rely on JS for validation of your forms. By all means have both, to save the user submitting the form only to find out they have entered fields incorrectly. But you should always have the server-side validation there, as the user can disable and modify the client-side JS. Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226089 Share on other sites More sharing options...
queketth Posted June 6, 2011 Author Share Posted June 6, 2011 I am not wanting to use it for validation merely to echo the validation results ... does this make any sense? Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226097 Share on other sites More sharing options...
fugix Posted June 6, 2011 Share Posted June 6, 2011 why not just continue to use php to do this instead of mixing php and js? Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226099 Share on other sites More sharing options...
queketth Posted June 6, 2011 Author Share Posted June 6, 2011 this is the site which i am trying to implement it on www.hqandco.com/contact.html try and submit the form and you will see what i mean the PHP alone looks really bad going to a separate page but i need that feedback to the user!! Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226105 Share on other sites More sharing options...
Adam Posted June 6, 2011 Share Posted June 6, 2011 Look at other sites- a lot link to a separate page but still retain the header and footer. A very simple way to achieve that, is by placing your header and footer mark-up within two separate files and including them with PHP before and after your echos. Very simple example: <?php require_once 'templates/header.php'; ?> <h2>Example Page</h2> <p>The header and footer are dynamically included into the page.</p> <?php require_once 'templates/footer.php'; ?> This approach also allows you to avoid duplicating the mark-up, so you don't have to make the same change across multiple pages. I don't know if you know much/any PHP, but it's not difficult to implement this, as you can see from the code above, to save yourself a lot of hassle and improve the consistency of your site's layout. You could also improve on it, using variables to dynamically set the title, description, etc. Bottom line though, you shouldn't be resorting to JS in order to get around problems like this. Quote Link to comment https://forums.phpfreaks.com/topic/238589-javascript-form-echo/#findComment-1226114 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.