Jump to content

Edit Multiple Records


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

Recommended Posts

Here is the code for using PHP/CDML to edit multiple records on one page.

This is the Format file which presents the data for editing. This example is using Checkboxes {yes,no} for each record:

<body>Hello World<br>

<form action="http://localhost/fmmultied.php" method="POST">

[FMP-Record]

[FMP-IF: yes_no .eq. Yes]

Yes<input type="checkbox" name="yes_no[]" value="[FMP-CurrentRecID]" checked>

[FMP-Else]

Yes<input type="checkbox" name="yes_no[]" value="[FMP-CurrentRecID]">

[/FMP-If]

<input type="hidden" name="rec_id[]" value="[FMP-CurrentRecID]"><br>

[/FMP-Record]

<input type="submit" value="Edit">

</form>

</body>





Here is the php script "fmmultied.php";


<?php



	$rec_ids = $_POST["rec_id"];

	$yes_nos = $_POST["yes_no"];

	

	for ($i = 0; $i < count ($rec_ids) ; $i++)

		{

		if (in_array ($rec_ids[$i],$yes_nos))

			{		

			$result = file_get_contents ("http://localhost:1154/FMPro?-db=combotest.fp5&-lay=multiedit&-format=ok.txt&-error=er.txt&-recid=" . $rec_ids[$i] . "&yes_no=Yes&-edit");

			}

		else

			{

			$result = file_get_contents ("http://localhost:1154/FMPro?-db=combotest.fp5&-lay=multiedit&-format=ok.txt&-error=er.txt&-recid=" . $rec_ids[$i] . "&yes_no=No&-edit");

			};

		} ;

		

	require ("index.html");

?>

The Format file "er.txt" and "ok.txt" have static content. They can be used to flag/log any errors that may occur.

Note that the function "file_get_contents()" is being used. Details of php functions etc can be found at:

http://www.php.net

Hope this is of interest.

Garry

Link to comment
Share on other sites

  • 1 month later...

I guess using the FX Class you are using XML requests rather than CDML. I saw a thread where somebody showed how to do multiple edits with the FX Class. Alternatively you can process the XML yourself without the FX Class.

The initial Form is still the same where you use an array. For example:

....

<input type="hidden" name="recid[]" value="[FMP-CurrrentRecID]"><input type="text" name="firstname[]" value="">

.....

The php script could look something like this:

<?php 



$rec_ids = $_POST["rec_id"]; 

$fnames = $_POST["firstname"]; 



for ($i = 0; $i < count ($rec_ids) ; $i++) 

{ 

$result = file_get_contents ("http://localhost:1154/FMPro?-db=combotest.fp5&-format=-fmp_xml&-recid=" . $rec_ids[$i] . "&firstname=" . $fnames[$i] . "&-edit"); 

} ; 



require ("index.html"); 

?> 

Hope this helps.

Garry

Link to comment
Share on other sites

GARRY!!!

You are the MAN!!!

After all of that cussing and shouting... My Co. Worker comes over to me and say's "ohh... you need to change your "status" to "status[]".

And it worked! I didn't even thing about the "[]".

I'm trying not to kick myself too hard.

Thank you so much for your help!!

Cheers!

Link to comment
Share on other sites

Hi Garry!

I was able to understand and get the edit functions to work. My problem was I kept getting warning and notices on the screen and treating them as ERRORS thinking it wasn't working. My brain was fried. I'm good now though.

I do have one question though. I may have come up with a method of "Finding Multiple Records" however, I'm not sure if it would be the way to go, but it's what I came up with.

Basically the user group would get a list. The then would select all they wanted to edit and click on a link that say's "Edit Selected".

I've worked this out with JavaScript & CDML before, by using a form field to keep track of the array (it's easier) then, set a form value equal to all of the requests and CDML would find them.

I'm kind of puzzled on this moving using PHP. Using FX, I can find one record with ease, even multiple ones, but it's all preset. Do you or anyone out there know of a way to do this type of backend transaction with ease?

Thanks a million!

Link to comment
Share on other sites

This can be done with PHP. I think the easiest way maybe to have an edit field in the Form. Your PHP script can check that field and only edit those records. For example (very brief):

HTML Form:

<input type="checkbox" name="editOK[]" value="yes">

PHP Script:

$editOK = $_POST["editOK"];

if ($editOK[$i] == "yes")

{

$editresult = file_get_contents("http://localhost:591/FMPro?-db.......&-edit");

};

Hope this leads you the direction of a solution.

Good Luck.

Garry

Link to comment
Share on other sites

HI Garry...

Thanks again for your input. I'm still kind of struggling with this, but I'm sure I'm headed the right direction. There is one thing I'm going to point out that all should know...

When using the code you posted for editing multiple records...

If you are going to be using a field that contains more than 1 value "word"...

Example: $addam = "Addam Driver"; and not $addam="AddamDriver"

wrap your "$tag" in the "rawqurlencode()" tag... This will parse it and properly send the information back to FMP.

Example: if $addam = "Addam Driver"...

You would right this as: rawurlencode($addam) in your http: request line.

This was causing me so many problems until I opened my PHP book and ran across it.

Hope this helps someone...

~Addam~

Link to comment
Share on other sites

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