Forums

Retrieve record from db with input of an element in form

na12 11 Dec, 2012
Hello,

I am new to Chronoforms, so as Javascript.

I am building a form to update student information. The form has student_id, name and several other fields (all text fields).
I want to be able to input student id and get the name from the student table and other fields from the project table.
I drag the Load JS action to the OnLoad event and added a 'blur' event to the student_id field using Javascript.

In Load JS action of OnLoad event:
          window.addEvent('domready', function() {
             $('student_id').addEvent('blur', function() {
               var id = $('student_id').value;
               id = id.trim();
               if (id.length <= 0)
                 alert("here ");
               else {
                 // Student id is not empty here, want to retrieve record from database, but how?
                 alert(id);
               }
             });
           });


I want to somehow get the record from the database when the 'blur' event of student_id if fired and the student_id is not empty (after student_id is input and lose focus).
The student_id 'blur' event is working, but where should I put the PHP code to get data from the database (in the same LoadJS action?) and how do I call it from the student_id 'blur' event function?

Thank you.
GreyHead 12 Dec, 2012
Hi na12,

You could do this with Ajax (check the FAQs for some more info) but it's easier to do with a two page form. Put the input for the ID on the first page, validate it and pass it to the second page where you can use a DB Record Loader to get all the information.

Bob
na12 16 Dec, 2012
Hi Bob,

Thanks for your response.

I couldn't find anything in the FAQs, would you email me the link if possible?
I did find this link: http://www.packtpub.com/article/adding-advanced-form-features-using-chronoforms
which has an example showing how to validate email address using AJAX. The example puts the PHP code in the "Extra Code" box. Where is the "Extra Code" box in the form wizard?

Thank you,

na12
GreyHead 16 Dec, 2012
HI na12,

You right there isn't much in the FAQs - a very small example in this one. The equivalent to the Custom Code box in Cfv4 is to use the Add Event button to add a new event to your form and then add a Custom Code action to that.

The document you found from the ChronoForms book is for CFv3, there's an updated version for CFv4 in a paid tutorial from my site here.

Bob
This topic is locked and no more replies can be posted.