Forums

Form change event, search and so on...

beregond 02 Jun, 2009
Hello first of all to all of you, and congrats to the developer of this great component.

I'll get straight to the point, I'm a total newbie when it comes to php and sql code-crunching so please bare with me.
The first form I've made in CF was for a basic email form for reservations of certain resources. That was a real breeze to make, even for me. However, now I've got a whole new project to complete and this must be simple and functional.

We are talking about a basic travel resource query system that needs pretty much the basics. I've made 4 forms that are hooked into separate mysql tables where data is stored:

- Add tour operator (Name)
- Add destination form (Name)
- Add city form (Name, Destination)
- Add resource (Name, Destination, City, Tour operator, Price....)

First thing I'm having problems is with the last form. I wish that when I choose the destination, the city field gets filtered down only to the cities that are linked to that destination. I.e. when I select France, I want that the City field shows only Paris, Lyon and Marseilles.....not Berlin, Amsterdam, Paris, Lyon, Rome. I've figured out that this is solved somehow using JS, but i have no serious clue how.

Here's the form HTML I've made till now:
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Destinacija</label>
    <select class="cf_inputbox validate-selection" id="select_1" size="1" title=""  name="select_1">

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT cf_id, text_0 FROM jos_chronoforms_destinacija ORDER BY text_0 ASC");
$events = $db->loadObjectList();
foreach ($events as $event) {
  echo ('<option value="' . $event->cf_id . '">' . $event->text_0 . '</option>');
}
?>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Grad</label>
    <select class="cf_inputbox validate-selection" id="select_2" size="1" title=""  name="select_2">

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT cf_id, text_0 FROM jos_chronoforms_dodaj_grad ORDER BY text_0 ASC");
$events = $db->loadObjectList();
foreach ($events as $event) {
  echo ('<option value="' . $event->cf_id . '">' . $event->text_0 . '</option>');
}
?>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Smještaj</label>
    <select class="cf_inputbox validate-selection" id="select_3" size="1" title=""  name="select_3">
    <option value="">Odaberite kategoriju</option>
      <option value="*****">*****</option>
<option value="****">****</option>
<option value="***">***</option>
<option value="**">**</option>
<option value="*">*</option>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Naziv</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_4" name="text_4" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_dropdown">
    <label class="cf_label" style="width: 150px;">Turoperator</label>
    <select class="cf_inputbox" id="select_5" size="1" title=""  name="select_5">

<?php
$db =& JFactory::getDBO();
$db->setQuery("SELECT cf_id, text_0 FROM jos_chronoforms_turoperatori ORDER BY text_0 ASC");
$events = $db->loadObjectList();
foreach ($events as $event) {
  echo ('<option value="' . $event->cf_id . '">' . $event->text_0 . '</option>');
}
?>

    </select>
    
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_datetimepicker">
    <label class="cf_label" style="width: 150px;">Datum polaska</label>
    <input class="cf_datetime required" title="" size="20" id="date_6" name="date_6" type="text" />
    
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Broj dana</label>
    <input class="cf_inputbox required validate-digits" maxlength="2" size="2" title="" id="text_7" name="text_7" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>
<br>
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Cijena (kn)</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="" id="text_8" name="text_8" type="text" />
  
  </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Dodaj u bazu" name="{cf_name}" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>


Also I would like to know is there a chance that the record gets deleted when the resource date is equal to the current one (basically, you can't send a query for something that happened yesterday)?


The second and the most biggest part of my troubles is how to use Chrono Connectivity to perform searches in the resources table? I want to have a search on the frontend where a visitor can select the Destination, date and the duration of stay, while the results show Destination, City, Name, Date, Tour operator (hidden to all except admins), Duration, Price and a link towards a booking form for each provided result.

If anyone is willing to help me out on this one, I'd would mean the world to me and also I would learn a good deal how things should work. Also, If I manage to get some refund from my client for who I'm working this for, I'll be happy to share a certain amount.

Apologies for an extensive post.

Cheers!
GreyHead 06 Jun, 2009
Hi beregond,

The best way to re-set your drop-downs is to use an AJAX call in the background. This is fairly easy to do with ChronoForms using the Extra Code boxes - I think that are some examples in the Forums here if you search on AJAX.

I don't understand your question about deleting records. If you don't want to show events that are in the past then add an extra clause to the WHERE for your database query to check that the event date is in the future.

For the ChronoConnectivity question you can use getUser to identify users and user groups and only show the extra fields to Admins. Search here on getUser for posts on the User object.

Bob
beregond 08 Jun, 2009
Hello Bob,

first of all, thanks for the reply!

Regarding record deletion. I've thought of an automatic way that the records get deleted from the database when they expire. Sure, it can be done manually, but if there's a way to make it automatic, why not...

So far I've made all the basics I need, but there's one last thing I need to get resolved in Chrono Connectivity. Hope someone can help me on this one.
This topic is locked and no more replies can be posted.