Steve21 Posted May 26, 2011 Posted May 26, 2011 </pre><form name="sports"></form><br><input type="submit" name="submit" id="submit" value="Submit" onclick="document.submitForm.submit();document.sub mitForm.rese that "should" be the issue" Replace submitForm with sports the document.sports is the form name you're submitting/resetting. Steve
CESIL Posted May 26, 2011 Posted May 26, 2011 Your form is submitting to the page that contains it...is that right? If so then as you are putting the $_POST data into the form fields then they will always be filled in... You need to clear out the $POST data after the data has been processed then the fields will be empty after form submissions.
Steve21 Posted May 26, 2011 Posted May 26, 2011 Can you try: Didn't think it was fussy enough but maybe it's being silly O.o or I'm just missing something obvious. Steve
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 Can you try: Didn't think it was fussy enough but maybe it's being silly O.o or I'm just missing something obvious. Steve That doesn't seem to be working.
CESIL Posted May 26, 2011 Posted May 26, 2011 The best way IMO to do this is to submit the form to a new page that processes the data and then returns the user to the form page...that should clear $_POST so that the form is blank...
CESIL Posted May 26, 2011 Posted May 26, 2011 @steve21 I don't think the javascript approach will work because the first statement submits the page to itself and I think the second statement will then not get run... The form reset function works for a button on a page to clear the form after it has been filled in but not after the form is submitted.
Edu-IT Posted May 26, 2011 Author Posted May 26, 2011 Not being a proficient coder I'm now proper confused!
Steve21 Posted May 26, 2011 Posted May 26, 2011 Sorry I disappeared, was busy at work. Can you try this: <br /> /*Contact form*/<br /> label {<br /> width:12em;<br /> float:left;<br /> text-align:right;<br /> margin-right:1.5em;<br /> display:block<br /> }<br /> .submit input {<br /> margin-left:4.5em;<br /> }<br /> input.text {<br /> border:1px solid #232a15<br /> margin:2px;<br /> border:1px solid #A8A8A8<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> textarea {<br /> border: 1px solid #232a15<br /> margin: 2px;<br /> border:1px solid #A8A8A8<br /> font-family:Verdana,Arial,Helvetica,sans-serif;<br /> }<br /> fieldset {<br /> border:1px solid #232a15<br /> padding: 4px;<br /> border:1px solid #A8A8A8<br /> }<br /> p.error, p.success {<br /> font-weight: bold;<br /> padding: 10px;<br /> border: 1px solid;<br /> }<br /> p.error {<br /> background: #ffc0c0<br /> color: #900<br /> }<br /> p.success {<br /> background: #b3ff69<br /> color: #4fa000<br /> }<br /> </pre><form name="sports" action="<?php%20echo%20basename(__FILE__);%20?>" method="post" onsubmit></form>="javascript:document.sports.reset();" ><br><noscript> </noscript><br> <fieldset> Name Pupils Name (if different) Tutor group Pupils sport/activity Pupils achievement E-mail </fieldset><br> Think I was being silly, and put it in wrong box Steve
Edu-IT Posted May 27, 2011 Author Posted May 27, 2011 Problem with that is that it appears to clear the form before it sends and I get: ERROR: Please fill in all the required fields and submit again. Please fill in all the required fields and submit again. Please fill in all the required fields and submit again. Please fill in all the required fields and submit again. Please fill in all the required fields and submit again. That is not a valid e-mail address.
Steve21 Posted May 27, 2011 Posted May 27, 2011 Problem with that is that it appears to clear the form before it sends and I get: Meh I dislike webstuff! Give me coding any day Honestly not sure, only thing I can think of doing is turning it into a function it calls. Then add the submit, then clear in that function. Steve
CESIL Posted May 27, 2011 Posted May 27, 2011 If you want the fields empty after form submission then why are you doing this The field will not be emptied if the form validation fails.
Edu-IT Posted May 27, 2011 Author Posted May 27, 2011 I give up. I think I'll find some other way of doing it.
webman Posted May 27, 2011 Posted May 27, 2011 Edu-IT: Make a new pastebin or update the old one with the current code you have, and please explain what you'd like it to and what it's doing wrong at the moment; and I'll have a look for you.
Edu-IT Posted May 27, 2011 Author Posted May 27, 2011 webman - Pastebin.com Trying to get it to submit the form and on submit, clear the fields. Ideally, also, instead of displaying multiple 'please complete all fields' just display the name of the frields that need to be completed. Something like 'Please enter your name, email address and message'. At the moment it just says 'please complete all fields' over and over again if you submit a blank form.
CESIL Posted May 27, 2011 Posted May 27, 2011 Sorry I wasn't trying to confuse you...honestly I think all you need to do is add code to set a flag once a successful submission has been made and then use that flag to decide whether to fill the form fields in or not. Something like this. Set flag to Not OK Do form validation If OK then submit data If successful set flag to OK If flag is OK Show form without data If flag is not OK then show form with existing data Does that make any sense?
CESIL Posted May 27, 2011 Posted May 27, 2011 (edited) Oops forgot the error message part... Instead of adding a complete sentence each time an error is detected as here if (!isset($_POST[$field]) || empty($_POST[$field])) $error_msg .= "Please fill in all the required fields and submit again.\r\n"; } Start the error message outside the test loop and just add the name of each field that is blank to the message $error_msg = "Please enter the following data, "; foreach($requiredFields as $field) { trim($_POST[$field]); if (!isset($_POST[$field]) || empty($_POST[$field])) $error_msg .= "$field,"; } $error_msg .= "\r\n"; Edited May 27, 2011 by CESIL Messed up the code!
CESIL Posted May 27, 2011 Posted May 27, 2011 @webman...nice idea using the error message as the flag...I should have thought of that but I am feeling a bit jaded today...might be because we celebrated my son's 21st last night
Edu-IT Posted May 27, 2011 Author Posted May 27, 2011 Perfect! Thanks :-D Anyway to remove the 'Submit: Submit' from email output?
webman Posted May 27, 2011 Posted May 27, 2011 You're welcome. Yes, you can. After line 88, you just need to remove the 'submit' key from the $_POST array (just add the 'unset()' function as shown below): ... if ($error_msg == NULL && $points <= $maxPoints) { $subject = "Automatic Form Email"; unset($_POST['submit']); $message = "You received this e-mail message through your website: \n\n"; ... CESIL: Might as well use something that's already there. It's not perfect, and if re-done from scratch I'd definitely change it. But it works
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now