943,844 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2106
  • PHP RSS
Jan 31st, 2006
0

Help with PHP and checkboxes

Expand Post »
Hi,

I'll explain basically what I'm trying to do.

A person goes to my site to download. Before they can download they have to agree to the TOS (according to my lawyer this is best). So on the page (let's call it agree.php) I need several things:

1. textarea with the TOS. This is no problem. I know how to do that.

2. a checkbox stating I have read and agree to the TOS. No problem input type=checkbox.

3. Validation. I can do client-side no problem (using JS) but I'm after server side validation.

Can someone tell me how to do this with php or recommend a good resource? I don't know much PHP or this would probably be simple. Here was my best guess:


<?php

/* Get URL to "goto" from POST var */

$agr = $_POST["agree"];

if ($agree == checked){
header("Location: http://www.downloadurl.com/");
}

elseif ($url != checked){
header("Location: http://www.nodownloadurl.com");
}

?>

Also if possible I was hoping to simple have the PHP write in at the top of the page 'You must agree to TOS' if they tried to submit without checking the box. Is that possible? Solutions and resources are appreciated.

I tried using the above, but it instantly redirected instead of waiting for the form to be submitted. :lol:



Greg
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
greghuston is offline Offline
11 posts
since Aug 2005
Jan 31st, 2006
0

Re: Help with PHP and checkboxes

My apologies for forgetting to use the code tags for the php code.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
greghuston is offline Offline
11 posts
since Aug 2005
Feb 1st, 2006
0

Re: Help with PHP and checkboxes

I assume you have 2 checkbox respectively named chk1 and chk2
then once the form is submitted if the first one is checked there will be something in your $_POST['chk1'] so you can do : if(isset($_POST['chk1'])) ...

you see?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
trafficman is offline Offline
64 posts
since Jun 2005
Feb 1st, 2006
0

Re: Help with PHP and checkboxes

ok checkboxs labelled correctly and when using isset it works fine. Thx for the help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
greghuston is offline Offline
11 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: need help in C/PHP
Next Thread in PHP Forum Timeline: Community Pack - Forum/Blog





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC