The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
Auto fill data in form - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: Auto fill data in form (/showthread.php?tid=5170) |
Auto fill data in form - kdo - May 14th, 2015 Hi all, I am working a project at the moment and I'm hoping to incorporate form tools as it looks like a great tool. The system is a martial arts membership database, what I'm trying to do is; - I have a list of members in a mysql db table - I want to create a form (e.g. for a tournament/competition, grading etc.) with some fields such as Name, email address, date of birth of the member - An instructor will login, select the member who's information should be pre-populated on the form, add some additional information and then submit it. - How do I tell form tools to auto-populate the form with the members information? (I've looked at option lists and these seem great, particularly loading data from another form, but I need to specify which member to load, not just giving the option of all of them?) I'm a PHP developer, so I can handle writing some PHP/JS to load the data into the form dynamically, but any pointers on where in the form tools code or within a module to do this would be great. Thanks Keith RE: Auto fill data in form - kdo - May 15th, 2015 So, this is a bit of a hack, but I decided to make use of the default value functionality and extend it to allow reading from the database. I found that the default values are read in ft_get_new_view_submission_defaults (in global/code/views.php) I couldn't find a hook for this function, so had to modify it directly. I am integrating this into another system, so I can push data into GET/POST variables and redirect the user to the add new submission page. I can then use those variables to construct a SQL statement that will load the correct data. So, in the default value for a field, I specify a string something like this: SQL:SELECT name FROM member WHERE member.id = '{{member_id}}'; {{member_id}} is a placeholder to read the value from $_REQUEST, so in ft_get_new_view_submission_defaults, I check for the "SQL:" at the start of the string, if it's present, substitute the variables, execute the query and store the result back as the default value. This is my new modified function; PHP Code: function ft_get_new_view_submission_defaults($view_id) |