Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-09-2010, 09:17 AM   PM User | #1
Genie1
Regular Coder

 
Join Date: Dec 2005
Posts: 149
Thanks: 12
Thanked 0 Times in 0 Posts
Genie1 is an unknown quantity at this point
Tick box to go next

Hello Guys,

I have a oscommerce store, for which i want to be able to make sure that if the tick box is not ticked then it will not go to the next page, so for example.

customer clicks on finish to order, but gets a popup saying please tick the box, and if ticked, the page just goes normal

THank you
__________________
Tomorrow Could Be Your Day
Genie1 is offline   Reply With Quote
Old 03-09-2010, 10:30 AM   PM User | #2
Shauny_B
New Coder

 
Join Date: Feb 2010
Location: UK, North West
Posts: 36
Thanks: 0
Thanked 5 Times in 5 Posts
Shauny_B is an unknown quantity at this point
Hello,
There are a couple ways of doing this, some being with client side validation, and server side... And of course both!

To check to see if they've "checked" the checkbox by either $_POST, or $_GET you need to do the following:

Lets say in this example we've got the form, with the input field checkbox, and name of it as chkAgreeExample:

Code:
<form....>

<input type="checkbox" name="chkAgreeExample" />

</form...
Now when the form is submitted, and you want the server side validation to pick it up do the following in PHP: This example I'm using $_POST superglobal, if you're submitting the form using $_GET use that instead of where I've written $_POST.

PHP Code:
if(isset($_POST))
{
    
/// other checks....

    #Lets check just for this option..
    
if($_POST["chkAgreeExample"] == "ON")
    {
       
# do magic here...
    
}
    
///.... blah blah blah

Now if you want to have a client side validation, you can capture the value of it by doing the following:

Code:
var checkBox = document.getElementById("YourIdOfCheckBoxHERE");
checkBoxValue = checkBox.value;
You can also use the jQuery library by doing this:

Code:
    $(document).ready(function(){
        if ($('#edit-checkbox-id:checked').val() !== null) {
        // Insert code here.
        }
    });
Hope this helps,
Shaun
Shauny_B is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 AM.


Advertisement
Log in to turn off these ads.