Closed Thread Icon

Topic awaiting preservation: Just One Checkbox (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13128" title="Pages that link to Topic awaiting preservation: Just One Checkbox (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Just One Checkbox <span class="small">(Page 1 of 1)</span>\

 
Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 04-10-2004 02:17

This is reduclously hard for me to understand... I'm writing a PHP page that has a checkbox on it.

code:
submit:
if it's checked
send 1
else
send 0

I know this has to be what's going on beneath the surface. After consulting a coleague, this was my response:
bmud: any suggestions?
Philihp: oh, checkboxes when unselected won't send anything but when they are selected, they send something like name=yes
Philihp: i think
Philihp: name=somethin
bmud: interesting
Philihp: is how html checkbox forms work
bmud: so, i should check for if the name equals the name?
Philihp: well, you could do, like on your submit page
Philihp: if(@$_GET['chkbox']=='yes')
Philihp: the @ will just repress any PHP_Notifications
Philihp: in case they are enabled
Philihp: the most common debugging thing in php
Philihp: that id o
Philihp: is to have a page
Philihp: that just has this:
Philihp: <?
Philihp: print_r($_SERVER);
Philihp: print_r($_POST);
Philihp: print_r($_GET);
Philihp: ?>
Philihp: (possibly enclosed in <pre></pre> tags)

Anyway... my form has the following:

code:
<form method="post" action="<?php echo $PHP_SELF?>">

So there isn't any pre-submit function that I can just add code to... yet? I'm really confused on this one.

At least this part works just fine:

code:
<input type="checkbox" name="visible" value="<?php echo $visible ?>" <?php echo (($id)?( ($visible == true)?('checked') :('') ) :('checked')); ?> />



[edit] smilies go off.. [/edit]

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation]

[This message has been edited by Bmud (edited 04-10-2004).]

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 04-10-2004 02:36

Bmud -

As you're sending the form's contents via the POST and not the GET method you'd need to check it like this:

code:
if (isset($_POST['visible'])) {
echo "Checkbox checked!";
}
else {
echo "Checkbox not checked!";
}



That way there's no need to repress PHP's warnings by using the @.

Though after reading your post again I'm not too sure any more if this really was your question. Was it?


kuckus

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 04-10-2004 02:41

And as for the debugging method your colleague mentioned, you can insert those lines just about anywhere in the file. I have them at the very beginning most of the time so the outputted information is the first thing I see when viewing the page in the browser.

Bmud
Bipolar (III) Inmate

From: Raleigh, NC
Insane since: Mar 2001

posted posted 04-10-2004 20:12

kuckus, that made everything make sense again. Thankyou. Now then, where would i put such a block of code as you suggested? The post command uses the action

code:
<?php echo $PHP_SELF?>

...can I change that to a function somehow that will run the checking before posting?

[edit] hey! some specifics! I'm using the post method to send the data to a mySQL database. The tinyint holds 1 or 0. [/edit]

Shine and shine. :: [Cell=992] :: [See my team's 30 second animation]

[This message has been edited by Bmud (edited 04-10-2004).]

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 04-10-2004 23:09

It's easiest if you assign a name to the form's submit button - then you can divide your PHP file up into two big parts, one for the form and one for the processing after data has been entered.

E.g.


<?php

if (!isset($_POST['submit'])) {
// the form hasn't been submitted yet -> display it

?>

<form .....>
...
<input type="submit" name="submit" />
</form>

<?php

} //closing the if block

else {

//the form has been submitted -> do whatever needs to be done with the varibles (something like the if/else from my first reply)

......

}

?>


If you've never done anything like this before then I'd suggest you have a look at my contact page tutorial over at the GN. Though you won't find any checkboxes there the PHP to handle the form data is very similar.
http://www.gurusnetwork.com/tutorial/contact_page/


kuckus

« BackwardsOnwards »

Show Forum Drop Down Menu