Set/Change field value on Begin Submit

  • actv-tec
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 41
  • Thank you received: 0

actv-tec created the topic: Set/Change field value on Begin Submit

Hello,
Is there a function to set a field value on "Submit pieces" -> "Begin Submit",
like there is a function to get value (ff_getSubmit).

Also is there a documentation with a list of all functions ?

Thanks
#226917
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2652
  • Karma: 92
  • Thank you received: 354

mihaela replied the topic: Set/Change field value on Begin Submit

Hello,

There is a function to set values ff_setValue('fieldname', 'wantedvalue'), but it can be used in Before form pieces.
You can find out more about Scripts and Pieces here crosstec.org/en/support/online-documenta...ript-and-pieces.html .

Here is what you can do to change the value of a certain field on submission. You should put the following code in End Submit Pieces.
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDBO();
$var1 = ff_getSubmit('field1');
if( $var1 != '1' ){
$db->setQuery("UPDATE `#__facileforms_subrecords` SET value = 1 WHERE name = 'field1' AND record = (Select max(id) FROM `#__facileforms_records`)"); 
$db->query(); 
}
Let's say you have a field named field1. The code above will check whether the filed's value is equal to 1. If it's not, it will change that value in the database to 1.

Another way would be to use validation scripts, to change the value of a field if necessary on submission. You would have to create a custom script like this:
function ff_elementname_validation(element, message)
{
    ff_getElementByName('elementname').value = 'wantedvalue';
    return '';
} // ff_elementname_validation
This would set the value of element named elementname to wantedvalue before submission.

Let me know if one of these solutions suits you.
If you have more questions, feel free to ask.

Regards,

Mihaela
#226953
  • webmaster@feuerwehr-muenchwilen.ch
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0

webmaster@feuerwehr-muenchwilen.ch replied the topic: Set/Change field value on Begin Submit

Hi,

your solution with the code in End Submit Pieces works perfect. Thanks.

But how can I change the values for the Admin-Email to?

Regards
Stefan
#237997
  • webmaster@feuerwehr-muenchwilen.ch
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 12
  • Thank you received: 0

webmaster@feuerwehr-muenchwilen.ch replied the topic: Set/Change field value on Begin Submit

Hello,

thanks for post. Changing values works fine with your solution.

BUT: How do I change the values for the admin and the replay email to?

Regards,
Stefan
#238000
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2652
  • Karma: 92
  • Thank you received: 354

mihaela replied the topic: Set/Change field value on Begin Submit

Hello,

The code provided in the End Submit pieces will change the values after the form is submitted since it will change the record in database.

Since email is sent right on submit, the email will contain incorrect values.

Therefore, to change values in the email here is what you can do.

1) Instead of putting the code in the End Submit pieces, you could change the fields values in the Begin Submit pieces like follows:
$this->execPieceByName('ff_InitLib');
$i = 0;
foreach($this->savedata as $data){
    if($data[_FF_DATA_NAME] == 'FIELDNAME'){
      if( $data[_FF_DATA_VALUE]) != 1 ) {
	      $this->savedata[$i][_FF_DATA_VALUE] = "1";
      } 
      break;
    }
    $i++;
}
NOTE: This code is written to work the same way as in my first post. So, it will check if value of a field is "1", and if it is not, it will set to that value.
You can remove the if condition if it is not needed in your case.

2) Another way would be to use validation scripts, to change the value of a field if necessary on submission. You would have to create a custom Validation script like this:
function ff_FIELDNAME_validation(element, message)
{
    if( ff_getElementByName('FIELDNAME').value != "1" ) {
        ff_getElementByName('FIELDNAME').value = "1";
    }
    return '';
} // ff_FIELDNAME_validation
This would set the value of element namedFIELDNAME to "1" before submission so it would basically work as in 1). The value would be changed both in record and email.

3) There is also a third options, if you are creating an email in End Submit pieces like here crosstec.org/en/forums/3-breezingforms-f....html?start=6#237911 , but if you are not, this is in my opinion too complicated solution.

I hope this will help you achieve what you want.
Let me know whether it helped and whether you have managed to set this for your form.

Regards,

Mihaela
#238013
  • mihaela
  • Away
  • Administrator
  • Administrator
  • Posts: 2652
  • Karma: 92
  • Thank you received: 354

mihaela replied the topic: Set/Change field value on Begin Submit

Hello,

The code provided in the End Submit pieces will change the values after the form is submitted since it will change the record in database.

Since email is sent right on submit, the email will contain incorrect values.

Therefore, to change values in the email here is what you can do.

1) Instead of putting the code in the End Submit pieces, you could change the fields values in the Begin Submit pieces like follows:
$this->execPieceByName('ff_InitLib');
$i = 0;
foreach($this->savedata as $data){
    if($data[_FF_DATA_NAME] == 'FIELDNAME'){
      if( $data[_FF_DATA_VALUE]) != 1 ) {
	      $this->savedata[$i][_FF_DATA_VALUE] = "1";
      } 
      break;
    }
    $i++;
}
NOTE: This code is written to work the same way as in my first post. So, it will check if value of a field is "1", and if it is not, it will set to that value.
You can remove the if condition if it is not needed in your case.

2) Another way would be to use validation scripts, to change the value of a field if necessary on submission. You would have to create a custom Validation script like this:
function ff_FIELDNAME_validation(element, message)
{
    if( ff_getElementByName('FIELDNAME').value != "1" ) {
        ff_getElementByName('FIELDNAME').value = "1";
    }
    return '';
} // ff_FIELDNAME_validation
This would set the value of element namedFIELDNAME to "1" before submission so it would basically work as in 1). The value would be changed both in record and email.

3) There is also a third options, if you are creating an email in End Submit pieces like here crosstec.org/en/forums/3-breezingforms-f....html?start=6#237911 , but if you are not, this is in my opinion too complicated solution.

I hope this will help you achieve what you want.
Let me know whether it helped and whether you have managed to set this for your form.

Regards,

Mihaela
#238014
Moderators: ForumSupporttomeperica
Time to create page: 0.056 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