General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 7th, 2003, 09:53 AM
Jad Jad is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 4 Jad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Form problem

greetings
I am working with forms,
The required fields will have same color as other fields
but if the user did not fill it i want to change the color to RED color
How can I do that with php and css ?


user name
password


now check if we have empty fields using
if(empty ($username) {
What should code here to change the color to red
}


username
Password *****
as you see the user forgot to fill his username but not the password
so only username color will changed to red

also my form is kinda very long
contain around 13 field till now
is there anyway to get all $_REQUEST['field']; at once? without repeating the
$username = $REQUEST['field'];
?
and is there anyway to check if field is empty with one code ? without repeating
if(empty ($fieldname)) {
}


Sorry for broken english
and thank you in adnvanced

Reply With Quote
  #2  
Old July 7th, 2003, 09:58 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
Post

you could do it with css....

PHP Code:
if( empty( @$_POST['var'] ) )
{
     <
input type=text name=name class=post_form_class>
}
else
{
     <
input type=text name=name class=not_post_form_class>

__________________
-- Jason

Reply With Quote
  #3  
Old July 7th, 2003, 10:26 AM
trystano trystano is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 45 trystano User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Why not use Javascript and CSS, and do the testing on the client-side? Otherwise you'll have to send all the information from the form to the server, and assuming not all the required fields are entered you'll need to reload the form and all the values that were entered back into the text boxes.
__________________
Tryst

Reply With Quote
  #4  
Old July 7th, 2003, 12:02 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 366 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 30 m 59 sec
Reputation Power: 7
well,..you can use JS and css,...but what if the client is setup to reject javascript?


Reply With Quote
  #5  
Old July 7th, 2003, 01:41 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Create an array whose keys correspond to the values you'll be reading in from the form. For example:

PHP Code:
 $fields=array(
    
"username"=array("","defaultStyleName"),
    
"password"=array("","defaultStyleName")
); 


When you process your form results, do something like the following:

PHP Code:
while(list($key,$val)=each($fields)){
    
$fields[$key][0]=$_POST[$key];
    if(
$_POST[$key]==""){ // or some other more complex validation test...
        
$fields[$key][1]="missingStyleName";
    }



Then when you're displaying your form, you can print the fields out as follows:

<input type="text" name="username" value="<?php echo $fields["username"][0]; ?>" class="<?php echo $fields["username"][1];?>">

This'll allow you to use the same code to print the original form and to reprint the form with posted values intact if there are errors.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Form problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT