1 2 Previous Next 17 Replies Latest reply on May 4, 2017 5:14 PM by charmcello

    More advanced CWP guide? (Need to handle checkbox fields)

    charmcello

      Hi,

      I'm relatively new to Filemaker PHP API and have almost completed development of a web registration form application.

       

      One of my remaining tasks is to take user input from a checkbox field and store that in a FMP database record. I'm having trouble finding step-by-step information on how to handle that.

       

      I have the FileMaker® Server 15 Custom Web Publishing Guide (fms15_cwp_guide.pdf) but it doesn't contain details about storing checkbox field data. Where could I find a step-by-step guide to handle specific situations not covered in the the CWP Guide? (And do you know where I could find info about handling checkboxes, specifically?)

       

      Thanks in advance.

      mikebeargie

      beverly

        • 1. Re: More advanced CWP guide? (Need to handle checkbox fields)
          mikebeargie

          Checkbox data in filemaker is stored as a return delimited list. So you just have to parse your form results into a return delimited list before you store it in FileMaker.

          1 of 1 people found this helpful
          • 2. Re: More advanced CWP guide? (Need to handle checkbox fields)
            charmcello

            Thanks for the quick reply!!

            So I use implode() to turn a PHP array into a string? How do I get the return delimiter?

            • 3. Re: More advanced CWP guide? (Need to handle checkbox fields)
              beverly

              Yes, or if you need to store otherwise (related records), the data may be able to be parsed after a single field insert or you use PHP to loop the values to create the records.

               

              1. how is your form defined with the checkboxes? can you post a few lines that are

              <input type="checkbox" ...

              2. how do you want it stored?

               

              the "advanced" guide may be HTML/JavaScript/CSS and/or PHP that goes beyond what the actual API classes handle. there are infinite combinations, so without a little more detail from you, it's not precise to say what to do.

              beverly

              • 4. Re: More advanced CWP guide? (Need to handle checkbox fields)
                charmcello

                Here is my html/php code snippet. Note that the values in the $payTypes array are directly imported as a value list from the database.

                 

                <label>How would you like to pay?</label>

                <div class="checkbox" id="paymentType">

                <?php

                foreach ($payTypes as $displayValue => $value) {

                   $string = str_replace(" ", "", $value);

                   $chk = ''; // Set $sel to empty initially

                   $tag = 'checked="checked"';

                   if($selectedpayType == $string) { $chk = $tag; }

                   echo '<label><input type="checkbox" id="'.$string.'"'.$chk.'>'.$value.'</label>&emsp;';

                }

                 

                I had to strip out the spaces in the values from the value list so I could use the resulting "$string"'s as jQuery-usable id's. Hope that makes sense.

                 

                I don't have my jQuery and $_POST stuff worked out yet. What I have isn't going to work, given the new information I've received.

                • 5. Re: More advanced CWP guide? (Need to handle checkbox fields)
                  beverly

                  checkboxes imply 0-all selection

                  radio buttons imply 0-1 (and only one is selected)

                  Payment type would have multiple choices?

                  • 6. Re: More advanced CWP guide? (Need to handle checkbox fields)
                    charmcello

                    Yes, unfortunately I've inherited kind of a kooky setup where payment type is a multiple choice thing. I intend to clean that up later so I can make this a radio button set, but for now, I just need to get the web form up and running.

                     

                    I have to leave it this way for now because, in the database, the value list includes some extraneous things that need to be able to be selected, along with payment type.

                    • 7. Re: More advanced CWP guide? (Need to handle checkbox fields)
                      beverly

                      <input type="checkbox"

                      can be changed to

                      <input type="radio"

                      Of  course if you are pulling data from a form (partially completed with multiple values), several radio buttons can be "checked". However, if this is a blank form with the selection-to-be-made. Try it.

                       

                      Then you should only return one item value to the field when submitted.

                      beverly

                      • 8. Re: More advanced CWP guide? (Need to handle checkbox fields)
                        charmcello

                        I'm not tracking with you? I need to be able to return multiple selections from this value list to the database, to comply with the frustrating way the value list was set up there.

                        • 9. Re: More advanced CWP guide? (Need to handle checkbox fields)
                          beverly

                          The "value list" in FileMaker is a set of return delimited values.

                          A Field is a field is a field. You can "optionally" format the field to be checkbox, radio, etc. (some value list to display) on the layout.

                          How it is formatted on the layout has nothing to do with need to pass the values. If the user "checks" 1 of 5, then only that one is returned. If the user checks 3 & 4 of 5, then those two are returned. ('Returned' means the actual value in the field without the formatting applied.)

                          The same on the web. You can select 0 or all of the values in a checkbox "type". What you check is what is returned. Processing is slightly different. But you do NOT need to check all of the values. And you will NOT get all the values back unless you have them all checked upon submit.

                           

                          It that what you need to do? return all values? (have them all checked by default)

                          beverly

                          • 10. Re: More advanced CWP guide? (Need to handle checkbox fields)
                            charmcello

                            No. I'll give you the specifics. The layout in the database has a checkbox field that I'm emulating on the web form. The value list for the checkbox field contains the following values:

                            Cash

                            Check

                            Money Order

                            Credit or Debit Card

                            Call before charging (<--- this one doesn't belong in this value list, IMHO... but it's there so I have to deal with it )

                             

                            So if a user selects "Cash", "Check", or "Money Order", they will probably only check ONE checkbox.

                             

                            However, if they check "Credit or Debit Card", they MIGHT also check "Call before charging". In that case, I'd need to submit TWO values to the database field.

                             

                            I think what you're saying is I can set up the fields how I want them in the web form, then massage the data after the fact so it fits with what the database wants. I guess I could do that.

                             

                            Either way, I need to know how to do a return delimiter in PHP in such a way that FMP will accept/recognize it 

                             

                            Can I do ASCII newline character:

                            $string_for_db_field = implode("\n", $array);

                            ?

                            • 11. Re: More advanced CWP guide? (Need to handle checkbox fields)
                              beverly

                              Ok. Data in one field that should be separated, but I'll go with that as, "I have done this too."

                               

                              Yes. Once all 'checked' items are in the field, you can post-process if that is easier for you.

                               

                              So what problem might you be having with the form or PHP or the API, if any?

                              Beverly

                               

                              Sent from miPhone

                              • 12. Re: More advanced CWP guide? (Need to handle checkbox fields)
                                charmcello

                                I need to know how to do a return delimiter in PHP in such a way that FMP will accept/recognize it.

                                 

                                Can I do ASCII newline character:

                                $string_for_db_field = implode("\n", $array);

                                ?

                                 

                                Or "\r" ?

                                "\n\r" ?

                                 

                                 

                                • 13. Re: More advanced CWP guide? (Need to handle checkbox fields)
                                  Stephen Huston

                                  Why not convert choices to radio with these mutually-exclusive choices:

                                  • cash

                                  • check

                                  • money order

                                  • debit or credit

                                  • debit or credit but call before charging

                                   

                                  That would eliminate the checkbox need.

                                  • 14. Re: More advanced CWP guide? (Need to handle checkbox fields)
                                    charmcello

                                    I need to stick with the value list I'm fetching from the database. I want my client to be able to make changes to the value lists in the database without having to hire a developer to fix the web form every time.

                                     

                                    Once I get the web form up and running, I will go into the database and see if I can change those fields and value lists without breaking anything in the database.

                                    1 2 Previous Next