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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New to the CF scene
    Join Date
    Jun 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I see Checkbox variable

    What would I use to display the selection after the submit button is checked?

    Code:
        
    <div>
          <input type="checkbox" id="burialtype" name="burialtype" value="1">
     		 <label for="burialtype"> Cremated</label>
          <input type="checkbox" id="burialtype" name="burialtype" value="2">
    		 <label for="burialtype"> Buried</label>
          <input type="checkbox" id="burialtype" name="burialtype" value="3">	
          	 <label for="burialtype"> Buried - Unknown</label>
          <input type="checkbox" id="burialtype" name="burialtype" value="4">
          	 <label for="burialtype"> Buried - No Marker</label>   
          <input type="checkbox" id="burialtype" name="burialtype" value="5">
          	 <label for="burialtype"> Donated to Science</label>
        <div>
          <button type="submit">Submit form</button>
        </div>
    	   <echo burialtype>

  2. #2
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    Id's must be unique per element. You can't keep using the same name over and over again for an ID. Since the name element is the same for all of them you need to make them an Array.

  3. #3
    New to the CF scene
    Join Date
    Jun 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you help me with that?
    An example.

    Is there a better way to return a variable?
    I just need to set a variable to 1-2-3-4-5 and store it

  4. #4
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    Based on the name burialtype and the descriptions, it would seem the user should only be able to select ONE option which in that case, you should be using radio buttons.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  5. #5
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,080
    Thanks
    37
    Thanked 1,080 Times in 1,076 Posts
    As benanamen said you should be using radio buttons. And you don't say where you want to store the variable you get from this. And I personally do not like that 1-2-3-4-5 thing (which tells you nothing) when it is so much more elegant to use name/titles which are far more descriptive.

    Here's how to do it with PHP:
    The HTML:
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    
    </head>
    
    <body>
    
    <form id="burialForm" method="POST" action="test.php" >
    <input type="radio" id="Cremated" name="burial" value="Science">
    <label for="Cremated"> Cremated</label><br>
    
    <input type="radio" id="Buried" name="burial" value="Buried">
    <label for="Buried"> Buried</label><br>
    
    <input type="radio" id="Unknown" name="burial" value="Unknown">	
    <label for="Unknown"> Buried - Unknown</label><br>
    
    <input type="radio" id="No_Marker" name="burial" value="No_Marker">
    <label for="No_Marker"> Buried - No Marker</label><br> 
    
    <input type="radio" id="Science" name="burial" value="Science">
    <label for="Science"> Donated to Science</label><br>
    
    <button type="submit">Submit Form</button>
    </form>
    	   
    </body>
    </html>
    The PHP:
    PHP Code:
    <?php
    $typeBurial 
    $_POST["burial"];

    switch(
    $typeBurial) {
        case 
    "Cremated":
            echo 
    "Cremated";   // Put what you want done here
            
    break;
        case 
    "Buried":
            echo 
    "Buried";
            break;
        case 
    "Unknown":
            echo 
    "Unknown";
            break;
        case 
    "No_Marker":
            echo 
    "No Marker";
            break;
        case 
    "Science":
            echo 
    "Donated to Science";
            break;        
        default:
            echo 
    "Did not get that";

    ?>
    If you want to store the variable in javascript -
    Change the button to an input
    use onclick to call JS function
    See This:
    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    
    </head>
    
    <body>
    
    <form id="burialForm" method="POST" action="test.php" >
    <input type="radio" id="Cremated" name="burial" value="Science">
    <label for="Cremated"> Cremated</label><br>
    
    <input type="radio" id="Buried" name="burial" value="Buried">
    <label for="Buried"> Buried</label><br>
    
    <input type="radio" id="Unknown" name="burial" value="Unknown">	
    <label for="Unknown"> Buried - Unknown</label><br>
    
    <input type="radio" id="No_Marker" name="burial" value="No_Marker">
    <label for="No_Marker"> Buried - No Marker</label><br> 
    
    <input type="radio" id="Science" name="burial" value="Science">
    <label for="Science"> Donated to Science</label><br>
    
    <input type="button" onclick="subAndStore()" value="Submit Form">
    </form>
    
    <script>
    function subAndStore(){
    	var howBuried = document.querySelector('input[name = "burial"]:checked').value;
    	document.getElementById("burialForm").submit();
    }
    </script>	   
    </body>
    </html>
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  6. #6
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    I personally do not like that 1-2-3-4-5 thing (which tells you nothing) when it is so much more elegant to use name/titles which are far more descriptive.
    If we are dealing with a properly normalized database, then the OP's value numbering would be the proper way to handle it.

    OP since you have not specified how you want to "store it" we are not able to give you a complete precise answer.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  7. #7
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,080
    Thanks
    37
    Thanked 1,080 Times in 1,076 Posts
    If we are dealing with a properly normalized database, then the OP's value numbering would be the proper way to handle it.
    Really? You need to explain that. I believe you would look up the person by name and query his/her method of internment and getting a 4 as the method of body disposal wouldn't help at all.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  8. #8
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    Quote Originally Posted by sunfighter View Post
    Really? You need to explain that. I believe you would look up the person by name and query his/her method of internment and getting a 4 as the method of body disposal wouldn't help at all.
    The OP changed what he wanted in Post #3. He went from displaying (Post #1) to Storing (Post #3) so we are now talking about adding data instead of displaying it which is what my reply was based on.

    I just need to set a variable to 1-2-3-4-5 and store it
    If OP wanted to ADD and DISPLAY, then you would include the logic you posted for the display but using the numbered keys instead of a name. The DB would store the number which is a key to the burial_types table.

    A lookup is not relevant to this post since we are not editing or displaying data already entered.
    Last edited by benanamen; Jun 11th, 2017 at 08:28 PM.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  9. #9
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,080
    Thanks
    37
    Thanked 1,080 Times in 1,076 Posts
    The DB would store the number which is a key to the burial_types table.
    OK, I see your privy to more data then I am, Anyway all the OP needs to do is change the value in my code back to numbers., if he/she ever comes back so many posters never do.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  10. #10
    New to the CF scene
    Join Date
    Jun 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry,
    But my amateurish attempt at coding and not fully understating the table structure of the existing pages muddled the water.

    I agree that radio buttons are the way to go - (Only one selection)

    I was using burialtype for all as the variable and setting the value to 1-5.
    The existing People Table has burialtype at column 20 and has existing numeric values
    A value of "0" directs the getperson.php to construct the Individuals Information page with a row "Burial"
    If a value of "1" is encountered it builds a row "Cremated"

    This is the code in admin_editperson.php which creates the existing checkbox "Cremated" and if checked sets the Value of burialtype to "1" when saved.

    PHP Code:
    <?php
        
    echo showEventRow('birthdate','birthplace','BIRT',$personID);
        if(!
    $tngconfig['hidechr'])
            echo 
    showEventRow('altbirthdate','altbirthplace','CHR',$personID);
        echo 
    showEventRow('deathdate','deathplace','DEAT',$personID);
        echo 
    showEventRow('burialdate','burialplace','BURI',$personID);
        
    $checked $row['burialtype'] == " checked=\"checked\"" "";
        echo 
    "<tr><td></td><td colspan=\"3\"><input type=\"checkbox\" name=\"burialtype\" id=\"burialtype\" value=\"1\"$checked/> <label for=\"burialtype\">{$admtext['cremated']}</label></td></tr>\n";
        if( 
    $rights['lds'] ) {
            echo 
    showEventRow('baptdate','baptplace','BAPL',$personID);
            echo 
    showEventRow('confdate','confplace','CONL',$personID);
            echo 
    showEventRow('initdate','initplace','INIT',$personID);
            echo 
    showEventRow('endldate','endlplace','ENDL',$personID);
        }
    ?>
    This is the portion of the code in getperson.php that builds the page with either a "Buried" or "Cremated"row

    PHP Code:
            doCustomEvents($personID,"I");

            
    setEvent( array( "text"=>$text['died'], "fact"=>$stdex['DEAT'], "date"=>$row['deathdate'], "place"=>$row['deathplace'], "event"=>"DEAT""entity"=>$personID"type"=>"I" ), $row['deathdatetr'] );
            
    $burialmsg $row['burialtype'] ? $text['cremated'] : $text['buried'];
            
    setEvent( array( "text"=>$burialmsg"fact"=>$stdex['BURI'], "date"=>$row['burialdate'], "place"=>$row['burialplace'], "event"=>"BURI""entity"=>$personID"type"=>"I" ), $row['burialdatetr'] );
        } 

  11. #11
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    The existing People Table has burialtype at column 20
    If you have 20 columns in one table your DB design is likely wrong. Post an SQL dump of your DB with a few sample records and we will review it. You can also PM it to me.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  12. #12
    New to the CF scene
    Join Date
    Jun 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by benanamen View Post
    If you have 20 columns in one table your DB design is likely wrong. Post an SQL dump of your DB with a few sample records and we will review it. You can also PM it to me.
    This is only one table of > 30 tables used by the program.
    It's an open architecture Genealogy Data Base.
    The code is proprietary (I can't pass all of it - but users are free to modify)
    There are over 1,500 files that comprised the program

    Database Table List
    -screen-shot-2017-06-11-10.31.51-pm.jpg

    Database screen shot - (Sorry there is noting wrong with the structure)
    -screen-shot-2017-06-11-10.36.01-pm.jpg

  13. #13
    Senior Coder benanamen's Avatar
    Join Date
    Oct 2015
    Posts
    1,596
    Thanks
    10
    Thanked 162 Times in 157 Posts
    Sorry there is noting wrong with the structure
    And you know this how? I have never once seen anyone present a DB that did not have anything wrong with it.

    Pictures are less than useless. Without seeing the actual schema no one can really say, but it would appear there are indeed design issues. It's like if an Architect/Building Engineer wanted to know if a building was designed/built correctly and you just showed them a picture of the building. They need to see the actual blue print.

    I never asked to see any code. Just the DB design. You could PM it to me so it is not public. If "users" are free to modify the DB it shouldn't be a problem to provide the structure. You did say it was "Open".

    Edit: It would appear the OP is dealing with GEDOM, and if so, it makes no sense that it is a secret. From the description we find this:

    "The GEDCOM specification is far from perfect. There are various known errors and unnecessary limitations that should have been fixed a long time ago, but FamilySearch refuses to fix or update the specification."

    Sure sounds like the structure is known to be wrong. OP, you would get a lot better help if you had mentioned what the third party application is you are using.
    Last edited by benanamen; Jun 12th, 2017 at 05:06 PM.
    To save time, lets just assume I am almost never wrong.

    The XY Problem
    The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

    Make A Donation https://www.paypal.me/KevinRubio

  14. #14
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    8,080
    Thanks
    37
    Thanked 1,080 Times in 1,076 Posts
    @wkenddad,

    The HTML code I gave you in post #5 will work. Just change the value to the number for each radio input tag.
    Forget about the second code and look at the third one, which also stores your variable in javascript.

    Both the first and the third send the value to the PHP file of your choice, just change the form action variable to the name of the file.

    If your queries are working fast enough for you, I wouldn't worry about the DB structure. I've worked with DBs with three times that number of columns and it was fast enough. If it aint broke, don't fix it.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.

  15. #15
    New to the CF scene
    Join Date
    Jun 2017
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sunfighter View Post
    @wkenddad,

    The HTML code I gave you in post #5 will work. Just change the value to the number for each radio input tag.
    Forget about the second code and look at the third one, which also stores your variable in javascript.

    Both the first and the third send the value to the PHP file of your choice, just change the form action variable to the name of the file.

    If your queries are working fast enough for you, I wouldn't worry about the DB structure. I've worked with DBs with three times that number of columns and it was fast enough. If it aint broke, don't fix it.

    Thanks,
    When I place your code into the file using NetBeans 8.2 it shows errors.
    I've included the screen shot of NetBeans and the changes made to the original code which I posted above.
    I've also included a screen shot of the section of the page created by the code
    Can you see where the error is?

    Thanks again:

    -screen-shot-2017-06-12-5.51.21-pm.jpg

    -screen-shot-2017-06-12-5.52.52-pm.jpg


 
Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

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