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

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

Recommended Posts

  • Newbies
Posted

Hi,

I'm trying to tweak an existing web form to submit data to an FM7 DB using PHP. However, not all fields on the form are required and I cannot get the submit function to post to the database when any field is left empty. Does anyone have any ideas how to get it to post a new record when one of the fields is empty?

The setup of the page is pretty simple - the user populates the fields and then clicks submit. The page then posts the data to another page which runs it through a simple $_POST for each field. I've tried putting in a null (and 0) value in for the value of each field, but that doesn't seem to work. Thanks!

Posted

exactly what error message are you getting?

after your insert or update use


$result = $record->commit();



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

	echo $result->getMessage();

}




to find out.



this may help too



$myFieldVal = isset($_POST['myField'])?$_POST['myField']:"My Default Value";

  • Newbies
Posted

Hi,

The error message is:

Notice: Undefined index: AAI in C:InetpubRAPhandle_form.php on line 143

The line is repeated for each field left blank (and the associated $_Post line number).

My goal is to simply have the fields left blank in the DB record, so the fields don't have default values. Thanks for the help (again)!

-Dave

Posted (edited)

All fields have a default value. That value may be null, an empty string, 0, etc. But when the row is created something goes in the column.

I'm assuming that 'AAI' is the name of one of the fields and that the PHP Notice changes for each field. Using:


if(isset($_POST['AAI']){

    /* do something with $_POST['AAI'] */

}





Will stop the message but depending on how the rest of your page is written it may not be the problem with your submit (PHP Notices are informational only they don't halt or alter the how the code is processed code in any way.  They exist to let you know that php has run across something that may cause your code to not run as expected.).  



To fully troubleshoot your submit problem you need to know what the Filemaker error is after you perform the commit();  A couple of easy to miss gotchas that immediately come to mind are trying to set fields that are not on the layout you are using.  Filemaker's field validation is failing on one of your values.  



Knowing what your $_POST array contains might help you as well




print_r($_POST);




will tell you that.  Wrapping it in pre tags will make it a little more readable on the screen, although you can always just use view source to see the output with new lines in place.





The easiest way to set up and handle a simple web form submit for Filemaker is as follows:





/* For an Update */



$fields = $record->getFields();

foreach ($fields as $field){

	if (isset($_REQUEST[$field])) {

		$record->setField($field, $_REQUEST[$field]);

	}

}

$result = $record->commit();

 

/* For an Insert */



$layoutName = "myLayout";

$layout = $fm->getLayout($layoutName);

$insertVars = array();

$fields = $layout->getFields();

foreach ($fields as $fieldName => $fieldObject){

	if (isset($_REQUEST[$fieldName])) {

		$insertVars[$fieldName] = $_REQUEST[$fieldName];

	}

}

$newRecord = $fm->createRecord($layoutName, $insertVars);

$result = $newRecord->commit();



/*

it's a good idea to error check every major transaction so in either case followup with 

*/



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

    echo $result->getMessage();

}

This requires that all of your Filemaker Field names contain only letter, numbers, and/or underscores. No spaces or other characters (which IMHO is what you should be doing anyway). It also requires that each (or ) tag's "name" attribute contain the name of the Filemaker field it represents. I used $_REQUEST instead of $_POST because it contains both $_POST and $_GET values (i.e. works with both POST and GET html forms)

Edited by Guest
one more thing

This topic is 5810 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.