Forums

Can one combine a Submit(add) and Confirm(update) in 1 form?

Joe Stokes 23 Jul, 2012
Hi to all,

The challenge:
Develop a dynamic (content generated on the fly) form that will display a list of options per provider. The user can then select any number of options from the list and pre-book the activities.
Upon Submit, all the unselected options are excluded and the form only displays the selected items with pricing and totals based on the qty specified before Submit. In this process, new records are added into a number of tables.

The user then has the opportunity to either modify the selected quantities or to go back and re-select.

Once satisfied, the user then Confirms and the modified information is updated (not added) in the database.

My Solution:
A hybrid form was designed as data presented in the form is based on some complex queries spanning up to 12 different tables.
The selected option filtering after Submit is achieved with some custom SQL, php and HTML.

My Problem:
All works well up until the point of Confirming. Here I am stuck. I cannot get the form to respond on the Confirm.

I believe that I do not fully understand the workings of the Event Elements in CF so any assistance or guidance will be greatly appreciated.

The url of the beta site is: http://gateway2algarve.com/index.php?option=com_k2&view=item&id=1535:active-explorer-day-03&Itemid=188&lang=en
You will have to login before you can pre-book.
Use the following:
username: demo
Password: demo105

Thanks for a brilliant product and stunning support

Joe
(ps Bob, I can give you access to the back-end via PM if needed)
GreyHead 24 Jul, 2012
Hi Joe,

I'm not clear what you have there. The Confirmation page appears to be a form with no <form> tags - so the Submit button doesn't do anything.

Typically for a confirmation page you store the data in the user session and show a page which just displays the selections but is not editable - it's just a confirmation. Then after the Confirm button is clicked you go to the normal On Submit action and recover the data from the user session.

Bob

PS I wasn't clear why you have both a checkbox and a number input for the rows on the initial form?
Joe Stokes 24 Jul, 2012
Hi Bob,

Thanks for your quick response.😀

I'm not clear what you have there. The Confirmation page appears to be a form with no <form> tags - so the Submit button doesn't do anything.



That is correct, at the moment the Confirm button does nothing. The objective is to actually use the Confirm page as a second stage form, which will perform an update to the last inserted record.

Should I rather approach this as a multi-page form?
Alternatively, could I wrap the confirmation page in <form> tags and treat this as a form on its own? I was hoping that one of the events will handle that, but its OK if I have to use the tags.(However, I am not sure if one could have <form> tags within <form> tags, as I'm sure that somewhere in CF the normal <form> tags are added at run-time.)

Or could you suggest a more elegant approach? (I am eager to try anything) :wink:

I may be wrong, but it seems as if the DB Save function only allows for a "insert new record". Is there an "update record" feature that I may have missed? If there is none, it could come in as a very handy event plugin. 8)

[quote]PS I wasn't clear why you have both a checkbox and a number input for the rows on the initial form?[quote]

I understand why you ask this. For now, I just want to get the form's workflow and database actions working, then I can refine the "look and feel" of the form. The objective is that only the checkboxes will initially be displayed. The "number inputs" will initially be hidden. When the checkbox is selected, the associated number input field will display (onChange with AJAX)and the total for that row also calculated and displayed. This all happens at client side and is purely for (hopefully) better user GUI.😀 (Yet another nice challenge)

So to sum up:
1. Should I rather approach this as a multi-page from?
2. Alternatively, could I just add <form> tags and treat it as a form on its own? or
3. Is there a more elegant way do achieve what I need?

Then something that is off this topic:
You have events like load CSS file and load JS file. Would there be a load php file in the making or is there a way that one can call an external .php file in the custom code sections instead of copy and pasting the php code?

Thanks once again.

Joe Stokes
GreyHead 24 Jul, 2012
Hi Joe,

You can't have nested <form> tags and using the Confirmation page as a form is too complex to be worth while. The multi-page support in the current version is good and in this case I'd use that instead of going multi-form i.e. use one form with multiple pages rather than several linked forms.

The DB Save will update a record if a valid primary key value is included in the form data. If you keep the primary key in a hidden input in the form then you can update the record OK.

I include data from files into forms all the time. I even have a keyboard macro to do the including:
<?php
include (JPATH_SITE.DS.'components'.DS.'com_chronoforms'.DS.'includes'.DS.$form->form_details->name.DS.'load_js.js');
?>
This assumes that the file to be included is in the components/com_chronoforms/includes/[form_name] folder and you need to change the file name to suit. This code will work from a Custom Code action in any event or the Load JS action.

Bob
Joe Stokes 24 Jul, 2012
Hi again Bob,

This forum is working excellently as usual - help is at hand almost 24/7.

Multi page form will be the route - thanks for that advice.

One question regarding the primary key:
Is it fair to assume that when a primary key is set, an update would be performed and not an insert? And is that a hard and fast rule? (Just checking that I interpret everything correctly - I'm still new at this)

Regarding the include statement:
I am familiar with this and have attempted it in the form before with no results returned, but obviously did something wrong or left something out.
The question here is would I have to merge the data arrays from the include into the $form->data array to pass it through from one event to another, or can I just rely on the arrays returned by the include statement to be available when I need it?
Am I restricted to the path in CF directories as per your example, or can I have the files stored anywhere else in the site? (I use this method to extend some of my K2 templates functionalities and the files normally reside in the template/html/custom/ directory)

Thanks once again

Joe
GreyHead 25 Jul, 2012
Hi Joe,

ChronoForms uses the Joomla! Table Object 'bind', 'store' and 'save' methods. They follow the rules:

[list]
  • If there is a value set for the primary key and that value exists in the table then update the record.

  • If the primary key value doesn't exist, or there is no primary key value then create a new record.
  • [/list]
    There are some little quirks with the delete code that mean that this is only 100% reliable if the primary key is numeric so I always use an auto-incremented primary key. (If I need a unique identifier for public consumption then I use a random string stored in another column.)

    The include statement should work fine provided that you have a valid path to a readable folder. I just use that particular folder for convenience. If there is a problem it usually comes from a missing separator in the path string.

    There are several actions that can help with passing data depending on the exact needs.

    [list]
  • The Multi Page action in the Utilities group will handle passing data between pages in the same form (or between separate forms)

  • The Data to Session and Session to Data actions in the Session Data group do much the same but give you finer grained control if you need it (the Multi Page action basically combines these two).

  • The DB Save and DB Record Loader actions can also be used. These are needed if there is concern about data being lost, if the User Session may expire between pages, or if there is a need to access the data by a different user (for example with a Payment Gateway handshake confirmation).
  • [/list]

    Bob
    Joe Stokes 25 Jul, 2012
    Hi Bob,

    Thanks for your excellent advice.

    It is quite clear to me that I have a lot to research and learn about the Joomla! MVC and OO development.

    After some research, it seems as if the two most suitable IDE framewoks for application development with Joomla!, are Eclipse or Netbeans. Based on your experience and background, could you make any recommendation here as to which is the most suitable for a novice?

    Thanks again

    Joe
    GreyHead 25 Jul, 2012
    Hi Joe,

    Hmmm tricky question, I've used a bunch and seem to change every few years.

    I think the first was Zend Studio. As far as I remember that was good for PHP (as it should be) but not as good for other file types and quite expensive.

    Then a spell with Aptana Studio, which is based on Eclipse, that was quite good but got expensive and I recall it was messy to update.

    From that I switched to Eclipse. Free but there were so many options and plug-ins that it got difficult to be sure quite what I needed.

    When I wrote the ChronoForms book I tried Adobe DreamWeaver - there's a recipe on creating HTML in DreamWeaver - I liked that. The FTP worked smoothly, there weren't too many updates or changes. Though it's not especially PHP friendly it was good. It's also expensive but I gradually switched from Corel and built my portfolio of Adobe products so today I rent it as part of the Adobe Could package. But I don't use it any more.

    About six months ago I switched from DreamWeaver to Sublime Text 2. It's a paid editor but has an unlimited life trial with occasional nag messages. Sublime Text 2 is so far my favourite. It has a clean editing screen and a bunch of plug-ins (some a bit tricky to set up in Windows). The FTP works as smoothly as any other and there are linters (syntax checkers) and prettifiers for most of the code I use plus a wide range of other plug-ins and themes if you need them.

    I have used a few others (but not NetBeans) over the years but none for very long, usually I seem to stick with my current preference for a few years. The critical things for me are (a) smooth FTP so that I can connect to many sites and edit included code and (b) syntax checkers that will make finding my typos as easy as possible.

    Which is best is very much a question of personal taste . . . any of those I've mentioned here will do the basics perfectly well.

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