SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checkbox selected after submit

    Please someone tell me how I can show to the user what checkboxes he selected, after he clicks the submit button.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't he see that before he clicks submit? :P

    Maybe you have some code?

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sorin21us View Post
    Please someone tell me how I can show to the user what checkboxes he selected, after he clicks the submit button.
    Simply with $_POST variable. The selected checkboxes along with their respective values (that you put in the HTML) will be available for you in the $_POST super global array.
    HTML Code:
    <input type="checkbox" name="chk1" value="PHP" /> PHP
    <input type="checkbox" name="chk2" value="Javascript" /> JavaScript
    PHP Code:
    if(isset($_POST['chk1']) && !empty($_POST['chk1'])){
        echo 
    $_POST['chk1'];

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by rajug View Post
    Simply with $_POST variable. The selected checkboxes along with their respective values (that you put in the HTML) will be available for you in the $_POST super global array.
    HTML Code:
    <input type="checkbox" name="chk1" value="PHP" /> PHP
    <input type="checkbox" name="chk2" value="Javascript" /> JavaScript
    PHP Code:
    if(isset($_POST['chk1']) && !empty($_POST['chk1'])){
        echo 
    $_POST['chk1'];

    Thank you, but how can I put the selected sign on what was selected, instead of printing out that $_POST['chk1'] ?

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh you mean you will be in the same page/form after submitting the form? If so do something like this:
    PHP Code:
    <input type="checkbox" name="chk1" value="PHP"<?php echo if(isset($_POST['chk1']) && !empty($_POST['chk1'])) ? ' checked="checked"' '';?> /> PHP
    But be sure you submitted the form in the same page and page should remain containing the posted data.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No need for !empty with a checkbox, it will default to "on"

  7. #7
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by hash View Post
    No need for !empty with a checkbox, it will default to "on"
    Well it was just a kind of typo hash . I had just typed it for all post variables. Indeed that is not needed in case of checkbox.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Addict sorin21us's Avatar
    Join Date
    Mar 2009
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you rajug and hash. Now works.


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
  •