prefilling form with data NOT on url ($_POST?)

Status
Not open for further replies.

skyrun

Active Member
I have a fabrik form that accepts parameters and then builds a list of emails based on what was input.

Then i have another fabrik form that displays the results.

It works fine passing the form elements by url like this:

php onAfterProcess php plugin:
//... some other stuff to create $emaillist...//

echo "<script>window.location = 'group-text-email?option=com_fabrik&task=form.view&formid=168&rowid=&srms_group_email_text_preview___emaillist=".urlencode($emaillist).'</script>";

This script is the last line of the php form plugin on the first form.

however if the list is long (it could be hundreds or even thousands of emails)... i run into the limit of how long a url can be (get a 414 Request-URI too long).

  • one workaround would be to use SQL to build a new form row and point to that record when i redirect to the other form.
  • another option would be to send the element data to the new form NOT on the url, but as post data.
i think i prefer the 2nd option. are there examples somewhere on how to do that? would i have to code a onBeforeLoad to read the posted data and insert it into the fabrik data model?
 
Last edited:
I'm not really clear on what you are doing. The code you quoted seems to be a mix of JS and PHP, so I presume it's in a custom template or a calc element or some such. Is everything generated on page load, or can the email list be added to on the page?

In other words, can the emails be obtained when loading the seconds form, from data in the first form's table? Or might new addresses have been added on the page?

-- hugh
 
the js <script> above is echoed on a form 1 php plugin as a clumsy way to pass data from the php plugin to form2___element2 on the url. form2___element2 is actually srms_group_email_text_preview___emaillist in my example.

the summary is that i am trying to pass a very long string from form1 to form2 when i submit form1. it works if the string is short to do it the way i am doing it above, but i would like to know how to best pass an element to form2 without putting it in the url (since it could be too long).
 
UPDATE: i have been able to do it by setting $_SESSION['srms_group_email_text_preview___emaillist'] in the form 1 php onAfterProcess plugin like this:
PHP:
$_SESSION['srms_group_email_text_preview___emaillist']=$emaillist;
(then i redirect using the <script> above but no URL parameters).

Then in form 2, onLoad, i do:

PHP:
// get posted data from srms_group_email_text for prefilling this form data
$formModel->data['srms_group_email_text_preview___emaillist']=$_SESSION['srms_group_email_text_preview___emaillist'];


So it's working, even on very large $emaillist's. is this an ok way to do it?
 
Yup, that was going to be one of my suggestions. Although if the data is in form 1's table, I wouldn't bother with the session, just pass form 1's rowid in the URL, and load it from the database instead of reading from the session.

If you do use the session, I'd recommend making the session variable name more specific, by adding at least the rowid to it, and passing the rowid in the URL to build the name when getting the session.

Also, use the J! session API rather than pushing and poking $_SESSION directly.

-- hugh
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top