Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post

    Displaying results of a form entry (checkboxes and radio buttons)

    Hey guys!

    So I'm trying to echo the results of a form entry like this:

    PHP Code:
    echo "Type: ".$type." <br /"
    $type is a radio button. There are multiple of these and also check boxes. Nothing shows up with the above code.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Well, we can't help as we have NO idea how $type is defined.

    This is much akin to "My car isn't starting, its making this noise..."

  • #3
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    PHP Code:
    //VARS these are at the top of the page

    ....


    $year $_POST["year"];
    $stage $_POST["stage"];
    $difficulty $_POST["difficulty"];
    $type $_POST["type"];
    $title $_POST["title"];
    $details $_POST["details"];

    ....
    ..

    <!--- 
    TYPE --->
    <
    table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    form>
    <
    td><input type="radio" name="type" value="1" /> Repair<br /> </td>
    <
    td><input type="radio" name="type" value="2" /> Performance  </td>
    </
    form>
    </
    tr>
    </
    table
    Sorry!

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Wait, so where are you trying to echo this? I'm confused... so now we know where its defined, but not how you're using it? Should it be where "Repair<br />" is? What's the issue then?

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,021
    Thanks
    15
    Thanked 239 Times in 239 Posts
    Something you might be able to use here. Put a button in, next to the form, that calls a javascript function that displays the entries in the form in a div or popup window or alert box. The function just has to get the values of each entry.

  • #6
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    This is the check boxes:

    PHP Code:
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    form>
    <
    td><input type="radio" name="type" value="1" /> Repair<br /> </td>
    <
    td><input type="radio" name="type" value="2" /> Performance  </td>
    </
    form>
    </
    tr>
    </
    table
    Than you hit a submit buttons that runs a code that displays the data you submitted. In that code I'm using echo and the variable. But it doesn't work with the check boxes... I hope that clears it up.

  • #7
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Quote Originally Posted by zachatk View Post
    This is the check boxes:

    PHP Code:
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    form>
    <
    td><input type="radio" name="type" value="1" /> Repair<br /> </td>
    <
    td><input type="radio" name="type" value="2" /> Performance  </td>
    </
    form>
    </
    tr>
    </
    table
    Than you hit a submit buttons that runs a code that displays the data you submitted. In that code I'm using echo and the variable. But it doesn't work with the check boxes... I hope that clears it up.
    First, they're radio buttons, but we'll just go with a simple slip of the tongue on that Can you show us how they're being echoed after submission? If you print_r the _POST array, nothing is there?

    Also, I assume there's more code, including the submit button we don't see, right? (Side note, not a good habit to put a form tag between a row... structurally, you shouldn't have anything between table elements, except between td and th, where content is expected. I doubt this is the problem, but it can cause issues.)

  • #8
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    PHP Code:
    <!--- YEAR --->

    <form>
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <tr>
    <td><input type="checkbox" name="year[]" value="1" /> Any<br /></td>
    <td><input type="checkbox" name="year[]" value="2" /> N/A<br /></td>
    <td><input type="checkbox" name="year[]" value="3" /> 2000<br /></td>
    <td><input type="checkbox" name="year[]" value="4" /> 2001<br /></td>
    <td><input type="checkbox" name="year[]" value="5" /> 2002<br /></td>
    <td><input type="checkbox" name="year[]" value="6" /> 2003<br /></td>
    <td><input type="checkbox" name="year[]" value="7" /> 2004<br /></td>
    <td><input type="checkbox" name="year[]" value="8" /> 2005<br /></td>
    <td><input type="checkbox" name="year[]" value="9" /> 2006<br /></td>
    <td><input type="checkbox" name="year[]" value="10" /> 2007<br /></td>
    <td><input type="checkbox" name="year[]" value="11" /> 2008<br /></td>
    <td><input type="checkbox" name="year[]" value="12" /> 2009<br /></td>
    <td><input type="checkbox" name="year[]" value="13" /> 2010<br /></td>
    <td><input type="checkbox" name="year[]" value="14" /> 2011<br /></td>
    <td><input type="checkbox" name="year[]" value="15" /> 2012<br /></td>
    </tr>
    </table>
    </form>

    <br />
    <br />
    <br />

    <!--- TYPE --->
    <form>
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <tr>
    <td><input type="radio" name="type" value="1" /> Repair<br /> </td>
    <td><input type="radio" name="type" value="2" /> Performance  </td>
    </tr>
    </table>
    </form>

    <!--- STAGE --->

    <form>
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <tr>
    <td><input type="radio" name="stage" value="1" /> Stage 1<br /> </td>
    <td><input type="radio" name="stage" value="2" /> Stage 2<br /> </td>
    <td><input type="radio" name="stage" value="3" /> Stage 3<br /> </td>
    </tr>
    </table>
    </form>

    <!--- DIFFICULTY --->
    <form>
    <table align="left" border="1" cellpadding="3" cellspacing="10">
    <td><input type="radio" name="difficulty" value="1" /> Easy<br /> </td>
    <td><input type="radio" name="difficulty" value="2" /> Medium<br /> </td>
    <td><input type="radio" name="difficulty" value="3" /> Hard<br /> </td>
    </table>
    </form>


    <br />
    <br />
    <br />
    <!--- USER SUBMITTED INFORMATION --->

    <form action="verify_submit.php" method="post">
    <table border="0" cellspacing="0" cellpadding="3">
    <tr><td>


    </td></tr>
    </table>
    <br />
    <table>
    <tr><td>Title:</td><td><input type="text" name="title" maxlength="60" class="form" value="Title of Mod"</td></tr>
    </table>
    <br />
    <table>
    <tr><td></td><td>
    </table>
    <table>
    <textarea type="text" rows="10" cols="40" name="details" class="form" wrap="physical">Please give a complete and detailed write-up of instructions.</textarea></td></tr>
    </table>
    <br>
    <table>
    <tr><td <p><b>WARNING: Any spam will result in a instant termination of your account.</b></p>
    </table>
    <table>
    <input type="submit" value="Submit" class="btn" /></td></tr>
    </table>
    </form>


    <?
    }
    ?>
    That most of the code (some of the beginning is a whole new topic that I left out in the code). The submit button is on the bottom. I fixed the form thing btw. The user submitted forms actually work and display the data the user enters.

    The code I'm using to display this:

    PHP Code:
    <?
    //PROCESS FORM FOR MOD SUBMITIONS

    //VAR
    $year $_POST["year"];
    $stage $_POST["stage"];
    $difficulty $_POST["difficulty"];
    $type $_POST["type"];
    $title $_POST["title"];
    $details $_POST["details"];

    {
    echo 
    "Title: ".$title."<br /";
    echo 
    "Stage: ".$stage."<br />";
    echo 
    "Details: ".$details."<br />";
    echo 
    "Type: ".$type." <br /";
    echo 
    "Difficulty: ".$difficulty."<br />";

    }

    ?>

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Yah, easy reason your radio buttons aren't showing up: they aren't being submitted, they aren't in the form. They are in separate form tags, thus separate forms.

  • #10
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    Ok thanks I fixed that. But now I'm still sorta having problems. It displays the type (which is only 2 radio buttons). That's it (despite title and description). They are all coded similarly so I don't know why it isn't working!

    Thanks.

  • #11
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    So you're saying now it shows the type, but not the other 4 variables? Show your new code?

  • #12
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    PHP Code:
    <form action="verify_submit.php" method="post">



    <!--- 
    YEAR --->


    <
    table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    td><input type="checkbox" name="year[]" value="1" /> Any<br /></td>
    <
    td><input type="checkbox" name="year[]" value="2" /> N/A<br /></td>
    <
    td><input type="checkbox" name="year[]" value="3" /> 2000<br /></td>
    <
    td><input type="checkbox" name="year[]" value="4" /> 2001<br /></td>
    <
    td><input type="checkbox" name="year[]" value="5" /> 2002<br /></td>
    <
    td><input type="checkbox" name="year[]" value="6" /> 2003<br /></td>
    <
    td><input type="checkbox" name="year[]" value="7" /> 2004<br /></td>
    <
    td><input type="checkbox" name="year[]" value="8" /> 2005<br /></td>
    <
    td><input type="checkbox" name="year[]" value="9" /> 2006<br /></td>
    <
    td><input type="checkbox" name="year[]" value="10" /> 2007<br /></td>
    <
    td><input type="checkbox" name="year[]" value="11" /> 2008<br /></td>
    <
    td><input type="checkbox" name="year[]" value="12" /> 2009<br /></td>
    <
    td><input type="checkbox" name="year[]" value="13" /> 2010<br /></td>
    <
    td><input type="checkbox" name="year[]" value="14" /> 2011<br /></td>
    <
    td><input type="checkbox" name="year[]" value="15" /> 2012<br /></td>
    </
    tr>
    </
    table>

    <
    br />
    <
    br />
    <
    br />

    <!--- 
    TYPE --->

    <
    table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    td><input type="radio" name="type" value="Repair" /> Repair<br /> </td>
    <
    td><input type="radio" name="type" value="Performance" /> Performance  </td>
    </
    tr>
    </
    table>


    <!--- 
    STAGE --->


    <
    table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    tr>
    <
    td><input type="radio" name="stage" value="Stage 1" /> Stage 1<br /> </td>
    <
    td><input type="radio" name="stage" value="Stage 2" /> Stage 2<br /> </td>
    <
    td><input type="radio" name="stage" value="Stage 3" /> Stage 3</td>
    </
    tr>
    </
    table>


    <!--- 
    DIFFICULTY --->

    <
    table align="left" border="1" cellpadding="3" cellspacing="10">
    <
    td><input type="radio" name="difficulty" value="Easy" /> Easy<br /> </td>
    <
    td><input type="radio" name="difficulty" value="Medium" /> Medium<br /> </td>
    <
    td><input type="radio" name="difficulty" value="Hard" /> Hard<br /> </td>
    </
    table>



    <
    br />
    <
    br />
    <
    br />
    <!--- 
    USER SUBMITTED INFORMATION --->


    <
    table border="0" cellspacing="0" cellpadding="3">
    <
    tr><td>


    </
    td></tr>
    </
    table>
    <
    br />
    <
    table>
    <
    tr><td>Title:</td><td><input type="text" name="title" maxlength="60" class="form" value="Title of Mod"</td></tr>
    </
    table>
    <
    br />
    <
    table>
    <
    tr><td></td><td>
    </
    table>
    <
    table>
    <
    textarea type="text" rows="10" cols="40" name="details" class="form" wrap="physical">Please give a complete and detailed write-up of instructions.</textarea></td></tr>
    </
    table>
    <
    br>
    <
    table>
    <
    tr><td <p><b>WARNINGAny spam will result in a instant termination of your account.</b></p>
    </
    table>
    <
    table>
    <
    input type="submit" value="Submit" class="btn" /></td></tr>
    </
    table>
    </
    form
    verify_submit.php

    PHP Code:
    <?
    //PROCESS FORM FOR MOD SUBMITIONS

    //VAR
    $year $_POST["year"];
    $stage $_POST["stage"];
    $difficulty $_POST["difficulty"];
    $type $_POST["type"];
    $title $_POST["title"];
    $details $_POST["details"];

    {
    echo 
    "Title: ".$title."<br /";
    echo 
    "Stage: ".$stage."<br />";
    echo 
    "Details: ".$details."<br />";
    echo 
    "Type: ".$type." <br /";
    echo 
    "Difficulty: ".$difficulty."<br />";

    }

    ?>
    TYPE is the section that works.

  • #13
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    First things first.... your table scheme is HORRIBLY broken... you have an open td and tr AT LEAST. There cannot be any logical reason to use so many tables, and I am strongly among those who believe tables should not be used for layout... specially when all you're doing is setting up one row... its horribly convoluted, and your code is already broken with that alone.

    Throw print_r($_POST) to the top of the verification page and see what you get, just to make sure the vars are moving properly.

    I gave it a second look through, its quite possible the broken HTML is the reason its not working. You have an open td tag in there, which could be screwing with the results. Either way, fix the HTML (and strongly consider not using tables for layout) and check the _POST.

  • Users who have thanked Keleth for this post:

    zachatk (09-26-2010)

  • #14
    New Coder
    Join Date
    Sep 2010
    Posts
    77
    Thanks
    13
    Thanked 1 Time in 1 Post
    Ahh got it figured out! I took you advice and got rid of the tables. It didn't fix the problem though. One thing I didn't even realize is the \ for the double ""! So I worked it out and she's working like a bute! Thanks!


  •  

    Posting Permissions

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