BEFORE SUBMIT - Correct way to read and set form variables???

  • sharprez
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 27
  • Thank you received: 0

sharprez created the topic: BEFORE SUBMIT - Correct way to read and set form variables???

I'm trying to read a form variable....
change its contents.....
then save it with the form data.

My Before Submit Code:

$this->execPieceByName('ff_InitLib');
$myvar = ff_getValue('Video');
$myvar = $myvar+" something";
ff_setValue('Video',$myvar);

Image of form with field name is attached (just so you can be sure the variable exists).

Thanks
#227645
Attachments:
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: BEFORE SUBMIT - Correct way to read and set form variables???

Hello,

It is not possible to use ff_setValue function in End Submit. Therefore to achieve what you want I suggest you do the following.

1) Go to your form's Properties and set Include submit button to no.

2) To the end of your form add Submit button element and Name it submit

3) Go to Advanced options of that element and in the Actionscript section set Type to Custom and Action to Click. Then paste in the following code:
function ff_submit_action(element, action)
{
    
     ff_getElementByName("Video").value = ff_getElementByName("Video").value+ " something";
     if(typeof bfUseErrorAlerts != 'undefined'){
     JQuery(".bfErrorMessage").html('');
     JQuery(".bfErrorMessage").css("display","none");
    }
 
    
    error = ff_validation(0);
    if (error != '') {
        if(typeof bfUseErrorAlerts == 'undefined'){
           alert(error);
        } else {
           bfShowErrors(error);
        }
        ff_validationFocus();
    } else
        ff_submitForm();
} // ff_submit_action

Let me know if this works as you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela
#227646
  • sharprez
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 27
  • Thank you received: 0

sharprez replied the topic: BEFORE SUBMIT - Correct way to read and set form variables???

I'm pretty sure the title of my post is in regards to "BEFORE SUBMIT".
Any chance you can answer again before the next day?
#227652
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: BEFORE SUBMIT - Correct way to read and set form variables???

Sorry, my error, I wanted to write "It is not possible to use ff_setValue function in Begin Submit", not End Submit.

I assume that by Before Submit you mean the Advanced options > More options > Submit pieces > Begin Submit, is that right?

The ff_setValue function can for example be used in Before Form pieces. While End submit form runs the field's value is already set and can't be changed. At that point you can only get the value with ff_getValue function, but you can not change it.

The way to achieve what you want is to use this actionscript for submit button as explained.
function ff_submit_action(element, action)
{
    
     ff_getElementByName("Video").value = ff_getElementByName("Video").value+ " something";
     if(typeof bfUseErrorAlerts != 'undefined'){
     JQuery(".bfErrorMessage").html('');
     JQuery(".bfErrorMessage").css("display","none");
    }
 
    
    error = ff_validation(0);
    if (error != '') {
        if(typeof bfUseErrorAlerts == 'undefined'){
           alert(error);
        } else {
           bfShowErrors(error);
        }
        ff_validationFocus();
    } else
        ff_submitForm();
} // ff_submit_action

Another way to achieve what you want is to put code like the following in End Submit:
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$var1 = ff_getSubmit('Video');
$var1= $var1 . ' something';

$db->setQuery("UPDATE `#__facileforms_subrecords` SET value ='$var1' WHERE name = 'Video' AND record = (Select max(id) FROM `#__facileforms_records`)"); 
$db->query(); 
NOTE: If you decide to change value of Video field this way, the value that was entered in the form will be first saved and fox example sent by email, and afterwords when the record is already saved it will change that field value (add ' something').

The third way if you want to change field's value before submission, but you do't want to have custom submit button for some reason, you can add one line of code
     ff_getElementByName("Video").value = ff_getElementByName("Video").value+ " something";
to the validation script of that element. This way can be used only if Video is a required field in your form.

I hope everything is clear now. Let me know whether you manage to set this for your form.
If you have more questions, feel free to ask.

Regards,

Mihaela
#227658
The following user(s) said Thank You: sharprez
  • sharprez
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 27
  • Thank you received: 0

sharprez replied the topic: BEFORE SUBMIT - Correct way to read and set form variables???

Thank you! I have been using the second method. I was looking for an easier way.

I just wrote a nice detailed message, and the forum reported I wasn't logged in. (I was and still am) Maybe becuase I hit the Thank You button first?? (not important)

Here's the shortened version; I see this example in many places on this forum...

....AND record = (Select max(id) FROM....

A filter should be added for current User ID.. otherwise if two or more persons are adding a record..you don't know what your updating..(well, updating the last record, but that might not be yours).
#227670
  • Posts: 2823
  • Karma: 95
  • Thank you received: 379

mihaela replied the topic: BEFORE SUBMIT - Correct way to read and set form variables???

Hello again,

I understand what you mean. The first day is better in that case, because it would work right on submission and it wouldn't save the record first so there is no possibility for that to happen.

Despite that, he filter for current user ID can be added, but to make this work the submitter of the form has to be logged in when submitting the form otherwise it won't function well.

You would have to replace the old code with this one:
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$var1 = ff_getSubmit('Video');
$var1= $var1 . ' something';

$user = JFactory::getUser();

$db->setQuery("UPDATE `#__facileforms_subrecords` SET value ='$var1' WHERE name = 'Video' AND record =  (Select max(id) FROM `#__facileforms_records` WHERE user_id ='$user->id')"); 
$db->query(); 
This will check for the latest record from that user and update it.

Let me know if this works how you wanted.
If you have more questions, feel free to ask.

Regards,

Mihaela
#227699
The following user(s) said Thank You: magicican
Moderators: ForumSupporttomeperica
Time to create page: 0.072 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here