Different redirects in the same form and history of element when editing

Hi, it is possible to have in the same form two different redirect options, one to save or edit the form as per normal and another button ?invoice? that redirects to a different URL .
I am aware that the redirect pluggin has the option of selecting new or at edit but it is possible to add the option in there at apply or something like this. Without affecting the form when you select edit or save?

Keep track of editing

I want to know if there is an element that can keep record or all changes in the forms, for instance you save a form with 3 fields, name, tel, city (the 4th will be history), so the idea is that if after adding a record and you edit the telephone, then the history field will display that the telephone was change from OLD number to NEW number.
If this is not possible anyone has any ideas of how to get this done?

Thanks
 
  1. If you just want to be redirection without saving the form, then you can add an "invoice" button with the appropriate JS code attached to it to redirect to your "invoice" page.
If you want to save the form AND redirect to a different page as usual, then I think the easiest is to add a radio button element with "Invoice?" and "Yes/No" answer.
Attach the value "0" to No and "1" to Yes, then create a first redirect plugin, set the "usual" url as jump page and in the "condition" box of that plugin add the following code:
Code:
return $data == 0;
Then add a second redirect plugin, set its jump page to the "invoice" page and this type put this code in the condition:
Code:
return $data == 1;

2. For tracking, there is a for plugin call logs that sort of does this, but it is probably not as sophisticated as you need, so the way to go is to create your own PHP plugin that would run everytime the form is edited and that would record the information you need in its own dedicated table (that you have to create, using Fabrik or phpMyAdmin).
 
  1. If you just want to be redirection without saving the form, then you can add an "invoice" button with the appropriate JS code attached to it to redirect to your "invoice" page.
If you want to save the form AND redirect to a different page as usual, then I think the easiest is to add a radio button element with "Invoice?" and "Yes/No" answer.
Attach the value "0" to No and "1" to Yes, then create a first redirect plugin, set the "usual" url as jump page and in the "condition" box of that plugin add the following code:
Code:
return $data == 0;
Then add a second redirect plugin, set its jump page to the "invoice" page and this type put this code in the condition:
Code:
return $data == 1;

2. For tracking, there is a form plugin called logs that sort of does this, but it is probably not as sophisticated as you need, so the way to go is to create your own PHP plugin that would run everytime the form is edited and that would record the information you need in its own dedicated table (that you have to create, using Fabrik or phpMyAdmin).
 
JFQ's suggestions are essentially what I would suggest.

For the change history, your secondary table would look like this:

id (primary key)
parent_id (join element, pointing to the PK of your main table as the key)
phone_num

Then a form submission plugin, running "onAfterProcess", with some PHP like this:

PHP:
$db = JFactory::getDbo();
$this_phone = $formModel->getElementData('yourtable___phone_num', true);
$this_id = (int)$formModel->getElementData('yourtable___id', true);
if (!empty($this_phone && !empty($this_id)) {
    $query = $db->getQuery(true);
    $query->select("COUNT(*) as total")->from("your_change_table")->where('parent_id =  $this_id AND phone_num = ' . $db->quote($this_phone));
    $db->setQuery($query);
    $total = (int) $db->loadResult();
    if ($total === 0) {
        $query = $db->getQuery(true);
        $query->insert('your_change_table');
        $query->set('parent_id = ' . $this_id);
        $query->set('phone_num = ' . $db->quote($this_phone);
        $db->setQuery($query);
        $db->query();
}

Note that this would not only save different numbers, so if you changes it from 555 1212 to 555 1213, then back to 555 1212, it wouldn't record the last change. if you need it to do that, let me know, I'll tweak the query for you.

Obviously change the element names, etc to suit.

You would then be able to use the "related data" feature on your main table's List, to provide a link to a filtered list of the change table, showing changes for a given row on your main table.

-- hugh
 
Oh, and if you don't already enforce validation of specific formats for phone numbers, you'd probably want to tweak that to remove everything except numbers, like ...

$this_phone = preg_replace('/\s/', '', $this_phone);

... after the getElementData() line.

-- hugh
 
Hi Cheesegrits
Thanks you so much for the code. I didnt want to write anything until I fully understand it. but I could undertand a few things (I am sorry).
about parent_id:
is a joinelement, do you mean a databasejoin?
also what do you mean with pointing to the PK?
I guess if my from has more elemenets (i.e: phone number, city, school, so on)
I will have to copy paste the same code as many times as elements I want to watched right? leaving the smae first question
if (!empty($this_element && !empty($this_id))

Thank you so much for your time
Oh, and if you don't already enforce validation of specific formats for phone numbers, you'd probably want to tweak that to remove everything except numbers, like ...

$this_phone = preg_replace('/\s/', '', $this_phone);

... after the getElementData() line.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top