Forums

load external php for auto-fill form-fields

rmesman 05 May, 2009
Hi,

I'm trying to use an auto-fill in my form for addresses/places based on zip-code. I've found an example script which does what I need (with javascript and PHP) but I need this to work with CF. The example I've found retrieves the address and place from an external website, based on a given zip-code.

Basically the script works like this:
In a form I have a field ("pc") for the zip_code which calls a Javascript function by "onChange="getAddress(this.value)".
This "getaddress"-function is calling an php-file (getpc.php) which get the content of an url in which the 'address' and 'place' are being sort out. Then the fields 'address' and 'place' in the form are being updated with this data.

To make it short:
form->calls javascript based on "onChange"-> calls getpc.php-> gets data from other site -> fields in form are automatically being filled

I've tested this with just a plain form in php and it works. To make it work with CF I've included the Javascript-code in the Form-code-Javscript. All I need now is to put the 'getpc.php' file somewhere which is being called by the javascript.

Where to put this file, or if even better (?), where can I put this php-code?

Thanks,
Robin
GreyHead 05 May, 2009
Hi Robin,

There's an example in the forums here of a form that does this using Ajax in ChronoForms which works extremely well.

The answer to your question is that you can put the get.php file anywhere as long as you have the correct url in your calling Javascript.

In the current release of ChronoForms you can also put it into one of the Extra Code boxes in your Form. The calling url will then be
http://www.example.com/index.php?option=com_chronocontact&chronoformname=form_name&task=extra&format=raw


The task=extra parameter tells ChronoForms to use the code from Extra Code box 1 (you can use the others by specifying &extraid=2, &extraid=3, etc.). The format=raw parameter tells Joomla to send back just the output from the php without any header or templating stuff.

Bob
rmesman 05 May, 2009
Hi Bob,

Thanks for this fast reply. I'm not sure if I understand correctly but by putting the php-code in the Extra Code box, what this url does is that it is calling itself (the form), but going trough the extra php-code before loading itself again?

In simple:
form->Javascript->call itself through extra php-code->reload form with new data

Anyway, I will try both options (Extra Code box and the correct url in Javascript if using external file) and will reply a.s.a.p. which one worked best :-)

Thnx,
Robin
This topic is locked and no more replies can be posted.