Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

newEditCommand: having trouble with $_POST

Featured Replies

hello..

need a little help with editing a record. I have the Stark book, and the Olm book and still can't seem to make the "newEditCommand" work with $_POST. If i hardcode the the second parameter in "setField", things work fine. If i try setField('Name', $_POST['Name'].. i get an 'Undefined Index: Name' error.

here's my FIND and EDIT:


// FIND ATTENDEE RECORD

$request = $fm->newFindCommand('a');

$request->addFindCriterion('id', $_GET['id'] ); // 'id' is a random, alphanumeric field

$result = $request->execute();



	if (FileMaker::isError($result)) {

		echo 'Error: (' . $result->getCode() . ') ' . $result->getMessage() . "n"; exit;

		}



$attendees = $result->getRecords();

$attendee = $attendees[0];





// EDIT ATTENDEE RECORD

$message = '' ;



if (isset($_POST['submit']) && $_POST['action'] == 'edit' ) {

	

	$edit = $fm->newEditCommand('a', 6);   // does this HAVE to be 'recid'?

	$edit->setField('Name', 'Brian');   // doesn't work with $_POST['Name']?

	$edit->execute();

	$message = '

thank you

'; } ?>






here's the beginning of my FORM code:







  	

   

   

If you are trying to edit your selected attendee record with an edit command...:


<?php

// FIND ATTENDEE RECORD

$request = $fm->newFindCommand('a');

$request->addFindCriterion('id', $_GET['id'] ); // 'id' is a random, alphanumeric field

$result = $request->execute();



	if (FileMaker::isError($result)) {

		echo 'Error: (' . $result->getCode() . ') ' . $result->getMessage() . "n"; exit;

		}



$attendees = $result->getRecords();

$attendee = $attendees[0];





// EDIT ATTENDEE RECORD

$message = '' ;



if (isset($_POST['submit']) && $_POST['action'] == 'edit' ) {

	

	$edit = $fm->newEditCommand('a', $attendee->getRecordId());   // does this HAVE to be 'recid'?

	$edit->setField('Name', 'Brian');   // doesn't work with $_POST['Name']?

	$edit->execute();

	$message = '

thank you

'; } ?>

And it should work fine with $_POST[name].

Remember that it is case sensitive and ensure that the data is actually come through as you expect. Add this to the top of your code:

echo "

";

print_r($_POST);

echo "

";

die();

  • Author

thank you!! :

the books i have indicated i should pass 'recid' in a hidden field in the form, and then call it with a POST:


$edit = $fm->newEditCommand('a', $_POST['recid']);





and actually, getting the record this way worked fine.. but none of the 'setField' functions worked with POST then. They only worked if i hard coded the values. I thought i was making a mistake with regard to POST, but it sounds like my problem was with the way i was getting/assigning recid. This way (your way) works fine:





$edit = $fm->newEditCommand('a', $attendee->getRecordId() );

so, to follow up.. newEditCommand takes only the 'recid' as it's second parameter? It couldn't take something like my own random/alphanumeric 'id' field, right?

appreciate your help.

Edited by Guest

so, to follow up.. newEditCommand takes only the 'recid' as it's second parameter? It couldn't take something like my own random/alphanumeric 'id' field, right?

Technically speaking you are correct. However as the old saying goes there is more than one way to skin a cat.

The Filemaker_Record object has a setField() function so you could perform a find on your "own random/alphanumeric 'id' field" and as long as the layout returned with the find contains the field you wish to edit you can use the individual record object to write to the db:


// FIND ATTENDEE RECORD

$request = $fm->newFindCommand('a');

$request->addFindCriterion('id', $_GET['id'] ); // 'id' is a random, alphanumeric field

$result = $request->execute();



	if (FileMaker::isError($result)) {

		echo 'Error: (' . $result->getCode() . ') ' . $result->getMessage() . "n"; exit;

		}



$attendees = $result->getRecords();

$attendee = $attendees[0];



// EDIT ATTENDEE RECORD

$message = '' ;





if (isset($_POST['submit']) && $_POST['action'] == 'edit' ) {

	$attendee->setField('Name', 'Brian');  

	$update = $attendee->commit();

    if (FileMaker::isError($update)) {

		$message =  '
Error: (' . $update->getCode() . ') ' . $update->getMessage() . "";

	}else{

		$message = '

thank you

'; } }

  • Author

thanks everyone for your help.. i wanted to mention something else (rather important) that i picked up while building my first filemaker > php solution.

USE UNDERSCORES in your field names. A lot of my problems with $_POST had to do with "First Name" vs. "First_Name". I didn't know this ahead of time, of course, but i wanted to pass it along for those who might visit this thread in the future.

spaces are bad. :)

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.