Jump to content

Recommended Posts

Posted (edited)

Have a couple of issues with this form and wondering if anyone can help?

 

Here's the code I am using: http://pastebin.com/bEkihqgY

 

 

 

The problems:

  • If you submit the empty form, the error validation returns back "Please fill in all the required fields and submit again." twice. How can I get it to say the name of the fields instead?
  • The profanity filter doesn't work on the name field?

Edited by Edu-IT
Posted

Instead of outputting the error message each time an empty field is found you need to build a variable containing the names of the empty fields.

 

Then after you have looped through POST values test if the variable contains any value and then output the error message including the list of empty fields.

 

Another approach I have used in the past is to output a standard message and use css to highlight the empty fields by filling them with red or changing the border...

Posted

Something like this would also do it

if (!isset($_POST[$field]) || empty($_POST[$field]))
    $error_msg .= "Please fill in the $field field and submit again.\r\n";
}

 

BTW I like the 'orgasim' entry in your profanity list...shows how good sex-ed is doesn't it :)

Posted (edited)

Not me who wrote the code. ;-)

 

I'll adjust that, thanks. Any ideas why profanity doesn't cover the name field?

Edited by Edu-IT
Posted
I assume there's one of those for each field?

 

Yep, just stick the PHP script in the value for each one and change the $_POST['email'] to whatever

  • 3 weeks later...
Posted

Where am I going wrong here? Certain fields don't line up.

 

<br />
/*Contact form*/<br />
label {<br />
width:4em;<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 [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
margin:2px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
textarea {<br />
border: 1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
margin: 2px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
fieldset {<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
padding: 4px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
}<br />
p.error, p.success {<br />
   font-weight: bold;<br />
   padding: 10px;<br />
   border: 1px solid;<br />
  }<br />
  p.error {<br />
   background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0]#ffc0c0[/url]<br />
   color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900]#900[/url]<br />
  }<br />
  p.success {<br />
   background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69]#b3ff69[/url]<br />
   color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000]#4fa000[/url]<br />
  }<br />

</pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post">

 


    
    
    Name
    
   
    
    Pupils Name (if different)
    
   
    
    Tutor group
    
   
   
    Pupils sport/activity
    
   
   
    Pupils achievement
    
   
    
    E-mail
    
   
   
    
   
   
  </for

 

Tutor group, pupils sport, pupils achievement all display out of line.

Posted

Also I notice that on submit, the fields still retain data. Can this be cleared on successful submit?

 

And finally, how do I get the text area to retain entered data on error?

Posted

Simple answer to first bit :p

 

Your length of the name is too long. Change "name if different" etc, to "name" and it'll realign, as it's pushing it onto new line. (or incease size of column)

 

Steve

Posted (edited)
Simple answer to first bit :p

 

Your length of the name is too long. Change "name if different" etc, to "name" and it'll realign, as it's pushing it onto new line. (or incease size of column)

 

Steve

That's not it unfortunately.

 

Edit: Another thing I just noticed, when a field is not submitted, is it possible to just have the 'please complete all fields' messages displayed just once?

Edited by Edu-IT
Posted
That's not it unfortunately.

 

It is here :p Works fine.

 

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 [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
margin:2px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
textarea {<br />
border: 1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
margin: 2px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
fieldset {<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15]#232a15[/url]<br />
padding: 4px;<br />
border:1px solid [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8]#A8A8A8[/url]<br />
}<br />
p.error, p.success {<br />
   font-weight: bold;<br />
   padding: 10px;<br />
   border: 1px solid;<br />
  }<br />
  p.error {<br />
   background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0]#ffc0c0[/url]<br />
   color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900]#900[/url]<br />
  }<br />
  p.success {<br />
   background: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69]#b3ff69[/url]<br />
   color: [url=http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000]#4fa000[/url]<br />
  }<br />

</pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post">

 


    
    
    Name
    
   
    
    Pupils Name (if different)
    
   
    
    Tutor group
    
   
   
    Pupils sport/activity
    
   
   
    Pupils achievement
    
   
    
    E-mail
    
   
   
    
   
   
  </for

 

Works fine in IE8 now.

 

Steve

 

 

test.png

Posted
It is here :p Works fine.

 

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 [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br />
margin:2px;<br />
border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
textarea {<br />
border: 1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br />
margin: 2px;<br />
border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br />
font-family:Verdana,Arial,Helvetica,sans-serif;<br />
}<br />
fieldset {<br />
border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=232a15"]#232a15[/url]<br />
padding: 4px;<br />
border:1px solid [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=A8A8A8"]#A8A8A8[/url]<br />
}<br />
p.error, p.success {<br />
   font-weight: bold;<br />
   padding: 10px;<br />
   border: 1px solid;<br />
  }<br />
  p.error {<br />
   background: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=ffc0c0"]#ffc0c0[/url]<br />
   color: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=900"]#900[/url]<br />
  }<br />
  p.success {<br />
   background: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=b3ff69"]#b3ff69[/url]<br />
   color: [url="http://www.edugeek.net/misc.php?do=dbtech_usertag_hash&hash=4fa000"]#4fa000[/url]<br />
  }<br />

</pre><form action="<?php%20echo%20basename(__FILE__);%20?>" method="post">

 


    
    
    Name
    
   
    
    Pupils Name (if different)
    
   
    
    Tutor group
    
   
   
    Pupils sport/activity
    
   
   
    Pupils achievement
    
   
    
    E-mail
    
   
   
    
   
   
  </for

 

Works fine in IE8 now.

 

Steve

 

 

[ATTACH=CONFIG]10268[/ATTACH]

 

That worked, thanks. Must be something I did.

Posted
That worked, thanks. Must be something I did.

 

As I said :p Made label wider:

 

width:12em;

 

vs your 4em :D (or make names shorter)

 

 

What was other issue, it doesn't clear on input?

 

Steve

Posted
Perfect! Sorry. :-D

 

Anyone help with the PHP stuff?

 

You should be able to do a:

 

document.formname.reset();

 

After the submit to clear the boxes.

 

Steve

Posted (edited)
Where, sorry, after the closing fieldset?

 

There's few ways to do it, but cleanest (Think that word exists!)

 

Change:

 

 

 

to

 

 

Think that's right. (Obviously you need to put form name in though, which I don't think you did yet?)

 

Steve

Edited by Steve21
Posted
That retains all data still.

 

Have you named your form yet? Needs a named form to go against. In the original one it didn't have a name :p Can you post all what you're trying again please.

 

Steve

Posted

This is what I have.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...