Skip Navigation

[Resolved] Append Static date to field – add city, state to street address field

This thread is resolved. Here is a description of the problem and solution.

Problem:
Append Static date to field – add city, state to street address field before it get saved with CRED form

Solution:
you can use CRED hook "cred_before_save_data" to perform any customization before the post data is saved.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/append-static-date-to-field-add-city-state-to-street-address-field/#post-627645

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by pamb-2 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#627515

I'm using a CRED form to update a neighborhood issues tracking database.

I have a field type = "address" , named "home-owner-address". I want do display that address in a Content Template as a Google map.

The city and state will always be: "Palmetto, FL"

I don't want the users to have to enter, "Palmetto, FL" every time, just the house number and street.
I would like to automatically append "Palmetto, FL" to that field (home-owner-address) stored in the database.

I know how to fill a complete field with data with a function, but I don't know how to append it to user entered data.

Is there a function that I can run to do this on every new record save?

For example is the user enters into field "Address"
124 Main Street

It gets stored in the field as:
123 Main Street, Palmetto, FL

Thanks!

#627645

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - you can use CRED hook cred_before_save_data

For example - try to add following code to your current theme's functions.php file:

add_action('cred_before_save_data', 'my_before_save_data_action',10,1);
function my_before_save_data_action($form_data){
    // if a specific form
    if ($form_data['id']==9999){
        if (isset($_POST['wpcf-home-owner-address'])){
            $_POST['wpcf-home-owner-address'] = $_POST['wpcf-home-owner-address'].", Palmetto, FL"; 
        }
    }
}

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

#629690

Thank you, this worked beautifully!