Automatic form field filling from DB

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
PinkFloyd
Forum Newbie
Posts: 3
Joined: Tue Dec 19, 2006 7:45 am

Automatic form field filling from DB

Post by PinkFloyd »

Hello,

I've got a tricky one:

I'm making a GUI for a database containing error logs from a certain machine. These logs are written down manually from that machine and then entered into the database using my GUI.

I would like to do two things:

- Give the user the possibility to enter up to 10 log entries at a time
- Once the user enters the error code in one of the fields, and leaves that field, that code should be checked against another table in the DB, and if a description for that error already exists, it should auomatically be filled out in another field. If it doens't already exists, the user can input the description, and when submitting the form, not only update the error log table, but also the table containing the error codes and their descriptions.

I know I'm going far here, but there HAS to be a way. Parts can be done in PHP, parts in JavaScript, but both can't be combined because of the client-server difference, except maybe when using AJAX, of which I have no experience at all.

Anyone ? Anyone ?
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Well without using Ajax you are going to have to refresh your form once the user leaves the field to retrieve the description from the database,

or you could construct a javascript associative array (okay its objects and their properties, but for sake of not confusing issues lets treat them the same as PHP arrays) holding each possible error code and description. Then use javascript to retrieve the description from the array based on the errorcode as the index in the array.

Code: Select all

<script>
MyErrors['980X'] = 'An error';
MyErrors['981Y'] = 'Another error';
</script>
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

What are want to do here is fairly complex. Here's the form design I'd probably be looking at if you wanted to avoid ajax:
Legend wrote:field type => $fieldPostName = 'post value'

Code: Select all

+-- Error Logger -------------------------+ codes.php
|                                         |
|  +------------+                         | textarea => $codes
|  | 4          | Please enter all the    |
|  | 87         | error codes on separate |
|  | 12         | lines here.             |
|  | 6          |                         |
|  |            |                         |
|  +------------+                         |
|                                         |
|  <[ Proceed ]>                          | button => $submission
|                                         |
+-----------------------------------------+

+-- Error Logger -------------------------+ descriptions.php
|                                         |
|  +-------+----------------------------+ | table
|  | Code  | Description                | |
|  +-------+----------------------------+ |
|  | 4     | |xxxxxxxxxxxxxxxxxxxxxxxx| | | inputText => $code[4] pre-populated
|  | 87    | |xxxxxxxxxxxxxxxxxxxxxxxx| | | inputText => $code[87] pre-populated
|  | 12    | |xxxxxxxxxxxxxxxxxxxxxxxx| | | inpuTtext => $code[12] pre-populated
|  | 6     | |xxxxxxxxxxxxxxxxxxxxxxxx| | | inpuTtext => $newCode[6] this is a new one
|  +-------+----------------------------+ |
|                                         |
|  <[ Proceed ]>                          | button => $submission = 'proceed'
|  <[ Previous ]>                          | button => $submission = 'previous'
|                                         |
+-----------------------------------------+
use the submission from codes.php to generate descriptions.php. Use the submission from descriptions.php to create an UPDATE query from $_POST['code'] and an INSERT query from $_POST['newCode']
Post Reply