corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Radio Buttons


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP Radio Buttons
liamC
Member

Registered: 28th Feb 04
User status: Offline
16th Oct 08 at 13:08   View User's Profile U2U Member Reply With Quote

Is it possible to validate them if someone has forgot to choose one of the 3?
James
Member

Registered: 1st Jun 02
Location: Surrey
User status: Offline
16th Oct 08 at 13:24   View User's Profile U2U Member Reply With Quote

Yes but I haven't done PHP for years so can't remember how.

At a guess you would need to loop through each one, set a boolean value if one has been selected and then evaluate that boolean at the end.

There might be a neater way to do it but i'm a .Net man so I couldn't tell you.
chumbly_warner
Premium Member

Avatar

Registered: 22nd Aug 03
Location: Leicestershire
User status: Offline
16th Oct 08 at 13:40   View Garage View User's Profile U2U Member Reply With Quote

I dont like radio buttons, i prefer to use a dropdown and then atleast you know they have selected an item...
PaulW
Member

Registered: 26th Jan 03
Location: Atherton, Greater Manchester
User status: Offline
16th Oct 08 at 14:09   View User's Profile U2U Member Reply With Quote

just do a javascript function check before you pass to html, makes life easier (and quicker) for the user. also saves having to pass loads of shit back into the form from the phpscript for data already entered
ed
Member

Registered: 10th Sep 03
User status: Offline
16th Oct 08 at 14:11   View User's Profile U2U Member Reply With Quote

You'd validate them in the same way as you would in any language really. You're effectively doing the same thing, just using specific expressions.

You just want to check there is a value coming from the radio buttons, so you would use something like:

code:
if(!isset(radio_buttons)){
echo "You need to select an option from the radio buttons mate";
}


[Edited on 16-10-2008 by ed]
Sam
Moderator
Premium Member


Registered: 24th Dec 99
Location: West Midlands
User status: Offline
18th Oct 08 at 12:38   View User's Profile U2U Member Reply With Quote

Can't you just make one of them selected by default?

In the HTML output, something like:

<input type="radio" name="sex" value="male" checked="checked"> Male</input>

[Edited on 18-10-2008 by Sam]

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
corsa mfd Adam-D Help Zone, Modification and ICE Advice 6 184
19th May 04 at 19:30
by Adam-D
 
Display Problem with new cdr 500 cd player Lee_Heggie Help Zone, Modification and ICE Advice 1 1619
2nd Jul 04 at 19:31
by Richie
 
steering wheel radio remote control. boxmasher Help Zone, Modification and ICE Advice 7 193
13th Sep 04 at 19:40
by boxmasher
 
I-pod in your car Ludacris Turbo General Chat 11 1863
17th Jul 05 at 19:40
by mark87
 
Would this be PHP/mySQL or HTML/IMG SRC? liamC Geek Day 13 153
26th Jan 07 at 13:25
by aPk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Radio Buttons 29 database queries in 0.0118890 seconds