Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

newEditCommand: having trouble with $_POST


This topic is 5829 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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:







  	

   

   

Posted

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();

Posted (edited)

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
Posted

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

'; } }

Posted

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. :)

This topic is 5829 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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