Accessing Formulize Data From Other Modules/Systems
On www.xoops.org, eljkmw wrote:
I noticed that the "Member Registration" form that was created in Formulize has a "Location" field (in the SQL Formulize DB is "Location" under ele_caption). I have just installed the Liaise module, and created a Contact Us form. It reads the default values of {NAME} and {EMAIL} properly, but not {USER_FROM}. I found out, apparently that the "user_from" field (in the SQL Xoops User DB) is empty because the "Location" info is not written back into "user_from".My question is, how do I create a short PHP command in the Liaise module that can fill in the default value of "Location" from the Formulize DB for the user that is currently logged in?
Link:
http://www.xoops.org/modules/newbb/viewtopic.php?post_id=290796#forumpos...
This is an interesting side effect of using Registration Codes...only the basic information about the user account is stored in the regular user table, and all the information in the custom profile is stored in the formulize form. So Registration Codes does have this effect on modules that rely on other information in the user table, such as the instant messaging details, etc.
You can write a little PHP code and drop it into any XOOPS/ImpressCMS module, or any PHP system really, and get data from Formulize. This is where the details in the "Using Formulize and Pageworks..." PDF are relevant. You can get that PDF from the "Download" page of this website.
If you're already inside XOOPS/ImpressCMS, then the only thing you need is a function called "getData" and it's in a file called modules/formulize/include/extract.php.
If you are outside XOOPS/ImpressCMS then you need to specify the database connection credentials that are used in the mainfile.php. Details and examples for how to do this are in the PDF.
This is the basic code you're looking at to get your location information. The key thing you need to know is the element ID number of the question in the form that has the location information. You can get this by looking at the list of elements in the form, on the admin side, and looking at the status line while you hover over the Edit links. The "ele_id" parameter in the URL is what you need to know. That's the element id number.
You also need to know the form id number, which is the "title" parameter in the URL.
With that information, the code you need for your situation, looks more or less like this:
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/extract.php";
global $xoopsUser;
$elementID = 10; // use whatever the actual element id is that you need
$formID = 4; // use whatever the actual form id is that you need
// the third parameter in the getData function is the filter
// it is essentially the "WHERE" clause. Details are in the PDF.
// The filter below gets entries that were created by the current user.
// There should only be one entry that matches that, since everyone should have only one entry in the profile form
$data = getData("", $formID, "uid/**/".$xoopsUser->getVar('uid')."/**/=");
$entry = $data[0]; // getData always returns an array of entries, even if there's only one entry found
$location = display($entry, $elementID);With that code, you then have $location to work with, and you can print it out, assign it to a smarty template, modify it, do whatever you want basically.
Does this make sense? Let us know, thanks,
--Julian


Comments
Re: Accessing Formulize Data From Other Modules/Systems
Hi Julian -
I apologise for not responding sooner to your reply. I was caught up with work for last few months. Anyway, I realise that there could be a easier way to rectify this, by means of copying the value of the ele_id (ele_caption: Location) from Formulize to user_from (within the DB of xoops_user).
Is this possible? Help me, please :-)
Anyway, I created a new text box called "IP Address", and added the string below in the Default value portion -
<?php$default = $_server['remote_addr'];
?>
Unfortunately this didn't work. Where did I go wrong?
Please advise soon. Thank you.
Cheers,
Jason
Re: Accessing Formulize Data From Other Modules/Systems
Hi there,
If you were trying to make a default value in PHP for a Formulize textbox, then just leave out the
<?phpand
?>
tags. They aren't necessary. That should be it.
Does that help?
If you want to synch a custom field in the Formulize user profile form, with a field in the XOOPS user table, this should be very easy with triggers in MySQL and Formulize 3.0, since the data structure in 3.0 is transparent...each form is its own table. So you could easily write a trigger to keep this information in synch.
Formulize 3.0 is only at RC1 level, and if you have a very large data set, I would recommend waiting for RC2.
--Julian
Re: Accessing Formulize Data From Other Modules/Systems
Hi Julian,
Thank you for your help. I've removed the
<?phpand
?>
tags as you've advised, and the function works. Anyway, I would something 'extra' for this textbox called "IP Address". Apparently, the code is to detect the IP Address of the visitor, and automatically place the IP address onto the textbox. However, I want to 'disable' this textbox so that the visitor cannot amend the shown IP address when he/she is registering as a member on my website.
I've been searching high and low for solutions, but nothing has worked out. Could you please help me work your magic here?
Thank you.
Cheers,
Jason
Re: Accessing Formulize Data From Other Modules/Systems
Hello,
Isn't there an option for each form element, where you can "Disable this element for certain groups" and you pick the groups you want it to appear as a disabled element (ie: not editable) and that should be what you want, right?
Does that help?
--Julian
Re: Accessing Formulize Data From Other Modules/Systems
That feature may have been missing from 2.3. You may need to upgrade to 3.0 if you haven't already. It should be right on the admin page for every element, right below where you pick which groups can see the element, you can pick which groups you want the element to appear disabled for.
--Julian