SitePoint Sponsor

User Tag List

Results 1 to 22 of 22

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Me again! :) Quest. on radio buttons, checkboxes.. etc

    Guys....

    Just wondering.. can PHP have a function/s for the following GUI items:
    Radio Buttons
    Drop-down lists
    Checkboxes

    My idea in pseudo goes like this:

    if (client selects box1/button1)
    return TRUE

    if (TRUE)
    <Have PHP return a SELECT statement that views the stuff pertaining to if box1=TRUE.. etc).

    Possible? My knowledge of hard HTML code is weak.. I'm more of a WYSIWYG guy.. but I do know JAVA can do this (but i absolutely do not want to use JAVA! .

    Any way I can call these fns. in PHP or HTML? thanks!

  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well your check box will have a name value, say for example name="checkbox"

    So your code would be:

    if (isset($checkbox)) {
    do some stuff, or a select like you said
    }

    else {
    spit out an error in the users face
    }

    Remember checkbox's will be in an array most likely, if they all have the same name, then it would be name="checkbox[]"

  3. #3
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this code is PHP right.. not JAVA or HTML or stuff...

  4. #4
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is PHP. You might wanna learn some PHP before you implement it though ... otherwise things might get a bit complicated, hehe

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    infinitium, you seem to have a blury idea of what goes on at the web server and the client (the user's broswer). Think of PHP as a hamster (Mr Pythagoras HamPster to be exact) sitting at a typewriter inside the web server

    A request comes in to the Apache server for a web page. Lets say index.php Now if this page was just a plain old html page Apache wouldn't bother our twitchy fury friend but simply go to the file system read the file and send out its contents as a stream of data back to the client (the web surfer sitting at their browser). However, the requested page isn't a plain old html file. Apache knows this because it has a .php suffix on the file name. So Apache grabs the file index.php and instead of sending it out to the client, it sends it to Mr P. HamPster. Now, Mr P. HamPster is a multitalented fellow. He has a calculator, a typewriter and access to a filing cabinet full of index cards (a database) where he can search, sort, add, delete and update records.

    Mr P. HamPster reads all the code that is in the php file Apache gives him. Anywhere he sees a <?php ?> pair of tags he pays particular attention to what is inside those tags and performs whatever tasks are described therein. As he works away, he types up html (as directed by echo and print statements) which is sent back to Apache which in turn sends it off to the client - the user at their browser. When Mr P. HamPster has finished all the tasks assigned to him he goes back to manicuring his whiskers or whatever he does in his spare time.

    Consider the case of an html form. The user requests a page that contains a form. This request is received by Apache. The requested page may or may not need to be parsed by Mr P. HamPster, depending on whether it is an .html or .php file. However, one thing is for certain - the only thing that will be served back to the client (the user at their browser) will be HTML (perhaps with some JavaScript).

    When the user fills out the form in their browser and hits "submit" the client browser sends the form data by the POST method, along with a request for the file specified in the ACTION arguement in the FORM tag, back to the server. Eg:

    <form name="foo" method="POST" action="process_form.php">
    ... all your html for the form input elements goes here ...
    </form>

    Now the server receives this request along with the posted form data from the client. Because the requested file "process_form.php" is a php file, Apache finds the requested file and sends it along with the posted form data to Mr P. HamPster who analyses the form data according to the instructions inside the <?php ?> tags and follows its instructions. This could include analysing which checkboxes where checked and going to the filing cabinet and looking up some stored data and typing that up and sending it out to Apache who in turn sends it out to the client.

    In conclusion, as you can see, the only thing that Apache sends to the client is plain old HTML (with perhaps JavaScript which gets executed on the client side). The only person who gets to see the PHP code in its raw, natural naked beauty is Mr. P. HamPster (lucky devil).

    I hope that clears matters up even though I've told such a stupid story. I'm bored For more specific information that might be of relevence to what you want to do, check out Freddy's code in this thread. I found it amongst a whole stack of results by using the advanced search to search for threads that contained the keyword "checkboxes" in this (the PHP) forum.

    http://sitepointforums.com/showthrea...ght=checkboxes

  6. #6
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well put sid, when I have a son that is a definate bedtime story!

  7. #7
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHOA....!

    Thanks FreakySid.. nice story...

    Question: Why did the hamster settle for a job with no medical benefits, unpaid leave or a chance to mix/sniff around other cool female hamster chicks?



    Just a-wondering... thanks agaiN!

  8. #8
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And to think I thought sid mentioned that... but then again... don't think he did, waiting for the reason...

  9. #9
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by infinitium
    WHOA....!

    Thanks FreakySid.. nice story...

    Question: Why did the hamster settle for a job with no medical benefits, unpaid leave or a chance to mix/sniff around other cool female hamster chicks?



    Just a-wondering... thanks agaiN!
    You don't really think that all the money you pay your hosting provider for "bandwidth" is going to the Telcos do you? Those hampster are doing just fine thank you!

  10. #10
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As an aside to sid's hamsteriffic tale, be sure to check not only that the variable is set, but that it isn't equal to an empty string (or whatever leading value you might use - e.g., "-- List of Choices --" as an option in a select box)...depends on how you're structuring the content of your listboxes and whatnot, but I've run into trouble with the form elements being technicall SET because they're submitted - but no valid data was passed...

    Or maybe I'm just not a hampster chick - always managed to kill/release all my rodents somehow...



    Have fun!

    Mandi
    Love ya - mean it!

  11. #11
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mmm... ok.. this might sound silly... but how EXACTLY would I go about writing code to display checkboxes and radio buttons? would that code be in PHP or HTML...

    and timnz.. i don't get what you mean by :

    "Well your check box will have a name value, say for example name="checkbox"

    So your code would be:

    if (isset($checkbox)) {
    do some stuff, or a select like you said
    }

    else {
    spit out an error in the users face
    }

    Remember checkbox's will be in an array most likely, if they all have the same name, then it would be name="checkbox[]"

    what is isset? a reserved function call or something?

    thanks guys!

  12. #12
    SitePoint Evangelist ucahg's Avatar
    Join Date
    Apr 2001
    Location
    Sarnia, Ontario, Canada
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IsSet($variable) - check if the variable $variable exists. Returns true if it has been set, returns false if it hasn't been set.

    Go learn PHP, because this is fairly basic, and you won't understand anything if you do not have a basic knowledge of PHP.

  13. #13
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by ucahg
    IsSet($variable) - check if the variable $variable exists. Returns true if it has been set, returns false if it hasn't been set.

    Go learn PHP, because this is fairly basic, and you won't understand anything if you do not have a basic knowledge of PHP.
    Actually, I already know PHP a little... I've managed to get my php to talk to mySQL and SELECT, UPDATE and INSERT stuff.

    I'm just not sure on this "isSet" function... but after you clarified it, things are crystal clear!

    Now I need to know how to create/display checkboxes and radio buttons in either HTML or PHP. I can do those in JAVA, but I prefer not to bring JAVA in...

    anyone else can lend me a hand?

    thanks again!

  14. #14
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mr P. HamPster cannot create the checkboxes for you. They need to be created on the client (by the browser) and therefor must be coded in the HTML that gets sent to the client.

    If you read the thread I included the link to in my first post, you can copy and paste freddy's very simple script and try it out for yourself and you will see how the html, the form and php all interact.

  15. #15
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's how you make checkboxes and radio buttons in HTML:

    <input type="checkbox" value="whatever" name="whatever">

    if you want ones that are for the same "thing," name them the same with [] after the name and they'll come into PHP as an array of name. ex:

    <input type="checkbox" value="whatever1" name="whatever[]">
    <input type="checkbox" value="whatever2" name="whatever[]">
    <input type="checkbox" value="whatever3" name="whatever[]">

    and if you want one to be checked by default use the checked boolean attribute:

    <input type="checkbox" name="whatever" checked>

    with checkboxes, the corresponding value is ONLY sent if it is checked. so if it's not checked its name/value is NOT set in PHP.

    radio buttons - just name the ones that are in the same group the same name. and you can also use checked to set which one is selected first. ex:

    <input type="radio" value="whatever1" name="whatever">
    <input type="radio" value="whatever2" name="whatever">
    <input type="radio" value="whatever3" name="whatever">
    <input type="radio" value="whatever4" name="whatever">

    does that help?

  16. #16
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DR_LaRRY_PEpPeR
    here's how you make checkboxes and radio buttons in HTML:

    <input type="checkbox" value="whatever" name="whatever">

    if you want ones that are for the same "thing," name them the same with [] after the name and they'll come into PHP as an array of name. ex:

    <input type="checkbox" value="whatever1" name="whatever[]">
    <input type="checkbox" value="whatever2" name="whatever[]">
    <input type="checkbox" value="whatever3" name="whatever[]">

    and if you want one to be checked by default use the checked boolean attribute:

    <input type="checkbox" name="whatever" checked>

    with checkboxes, the corresponding value is ONLY sent if it is checked. so if it's not checked its name/value is NOT set in PHP.

    radio buttons - just name the ones that are in the same group the same name. and you can also use checked to set which one is selected first. ex:

    <input type="radio" value="whatever1" name="whatever">
    <input type="radio" value="whatever2" name="whatever">
    <input type="radio" value="whatever3" name="whatever">
    <input type="radio" value="whatever4" name="whatever">

    does that help?
    Perfect!! Thanks you guys... FreakySid.. will check out the link you provided....

  17. #17
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dude, some of you folks are MEAN! "Go learn PHP" - don't you think that's what lots of us on here are TRYING to do? It's not as if learning happens through osmosis...or through some Matrix-esque direct connection between our brains and some PHP guru's! At one time or another, you, too, were pondering mundane problems such as these. So lay off - if you're not interested in helping, don't answer the post!

    Anyway - glad inifintium got his problem solved.

    Mandi
    Love ya - mean it!

  18. #18
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hehe.. thanks Mandi,

    About time someone brought that up

  19. #19
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right-o....

    New question. How do I make it so a radio button can only be selected once? Meaning if you select another one button, the black marker jumps to that button etc....

    I remember some website doing this using EML or something lke that...

  20. #20
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just have the name attribute in the radiobox input the same,
    eg:
    <input type="radio" name="switch" value="1" />
    <input type="radio" name="switch" value="3" />
    <input type="radio" name="switch" value="4" />
    <input type="radio" name="switch" value="2" />

    And just add in a different value for each one.
    Oh no! the coots are eating my nodes!

  21. #21
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by timnz
    Just have the name attribute in the radiobox input the same,
    eg:
    <input type="radio" name="switch" value="1" />
    <input type="radio" name="switch" value="3" />
    <input type="radio" name="switch" value="4" />
    <input type="radio" name="switch" value="2" />

    And just add in a different value for each one.
    really.. that simple huh...

    My script as follows worked.. it was a checkbox before I switched to radiobuttons... never got to test it out.. but the radiobuttons worked in the end, before my post...

    PHP Code:
    <? while ( $row mysql_fetch_array($result1) ) {
               
               for (
    $y 0$y $x$y++) {  ?>
                       <input type="checkbox" name="foodtype[]" value="<?echo ("$row[$y]")?>"><? echo ("$row[$y]"); ?><BR>
                   <?}
        }
    ?>
    Anyway, it works now.. thanks a bunch anyways!

  22. #22
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mandi,

    I think the point people are trying to make is, you should learn the basics including HTML and javascript before diving into PHP. The questions asked here were simple html questions for the most part. If you are asking questions like this you need to get a better handle on html before you start learning PHP.

    Everyone started somewhere and I know I have come as far as I have by trying and doing, but I had to spend a lot of time learning the basics before any of this made sense, thats all people are trying to say.

    Also to address my number one pet peeve. Its Javascript not Java, they are two different things. All references to Javascript in this thread have been in the form of Java. Java is not javascript.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •