1 2 Previous Next 18 Replies Latest reply on Jul 29, 2016 10:22 AM by JoelShapiro

    Editing multiple portal rows - PHP

    RPaulH

      Based on a webpage by Joel Shapiro - Edit multiple FileMaker PHP records waaay faster... | F ’n’ web – FileMaker ’n’ the web: lessons learned - I am attempting to update multiple portal rows with PHP but am having no luck. Having used FM for many years but PHP on a few months I am sure that I am not fully understanding everything.

      These are the first two input rows of my form:

                    <td class="borders" align="center"><?php if( $record->getField('DateTAlert1')): ?><input type="text" name="<?php echo $childID ?>[tA1]" size="4" style="text-align:center;" value="<?php echo $T1YN ?>" /><?php ; endif; ?></td>

                    <td class="borders" align="center"><?php if( $record->getField('DateTAlert2')): ?><input type="text" name="<?php echo $childID ?>[tA2]" size="4" style="text-align:center;" value="<?php echo $T2YN ?>" /><?php ; endif; ?></td>

       

      This is the process after submit:

      if(isset($_POST['editalerts'])):

        // CAPTURE PARENT ID

        // and revert to actual FM record ID for the edit (from 'par11698' to '11698')

        $parent_id = str_replace('par', '', $_POST['parID']);

       

        // remove non-field elements from the $_POST array

        unset($_POST['parID']);

        unset($_POST['submit']);

       

        // START EDIT COMMAND (JUST ONCE, PER PARENT RECORD)

        $edit = $fm->newEditCommand('Edit_Alerts', $parent_id); // 'class' is the layout with the portal to registration records

       

        // FOR EACH PORTAL ROW, ADD FIELDS TO THE ONE EDIT COMMAND

        foreach ($_POST as $childID => $fields) {

      //var_dump($_POST);

        //exit;

          $edit->setField('PeopleJoin::TAlert1YN.'. $childID, $fields['tA1']);

          $edit->setField('PeopleJoin::TAlert2YN.'. $childID, $fields['tA2']);

          // setField format for related fields in a portal is: TO_name::fieldName.recID

          // note the dot (.) between fieldName & recID

          // e.g. $edit->setField('registration::fmField1.2938', 'yes');

          // remember, your TO name might be something like 'class_REG'

       

        }

       

        // EXECUTE THE EDIT

        $result = $edit->execute();

       

      If I dump the $_POST variables after the foreach ($_POST as $childID => $fields) it has all the correct data, I just can't seem to get it set in the fields. Someone please straighten me out.

        1 2 Previous Next