Access Gravity Forms fields on previous page (before pre-submit) - wordpress

Here's the sitch: I'm using a multi-page Gravity Form in conjunction with an external API.
On the first page of the form, the user supplies a phone number. On a subsequent page, I need to send the external API the phone number in order to retrieve the user's current settings, which then must be prepopulated in other fields.
I know how to use gform_post_paging, but since $entry hasn't been created yet I can't use it to pull fields from previous pages.
gform_pre_submission/gform_after_submission don't help me because I need to make the API call prior to users reaching the end of the form.
I've also tried handling this via jQuery, by pulling and storing the value of the phone field on page advancement (e.g. var phoneNum = jQuery('#input_2_25').attr('value');), but I get "undefined" no matter what when using field ids. (It works fine, in the same location, looking for other ids on the site, so the issue isn't with jQuery.) I'm guessing this means that between pages, the form elements don't exist in the view?
How can I accomplish this goal (i.e., retrieving a value from a previous page in a multi-page Gravity Form prior to the user reaching the end of the form)?

All of the data is stored in the $_POST variable on each page submission. Gravity Forms has a helper function for accessing $POST data. The format for the variable name will be 'input{fieldId}'.
$value = rgpost( 'input_1' ); // replace "1" with your field ID

Related

How to create a form where user gives details and also can check what he has entered on wordpress

I want to create a form on wordpress where the user will give the response and then the response is stored as csv , my problem is that i am using weforms and user are able to fill the form and response is stored also but i am not able to display the entries made by that user to himself so that he can change or view his entries later on also . I have made a website using buddy press where i need to take some data in the form so that the data is stored and the user can also check what he has entered and other members can also view his entries by going on his profile

Is it possible to pass a special query parameter value to a WooCommerce product link?

I am looking to use WooCommerce in a bit of a strange way, and I'm wondering if there is any way to make this possible. Here's my desired workflow:
Step #1: From a different site subdomain, provide a link to a certain virtual product, but with a query parameter with a unique user id number.
Explanation: The user is at othersite.example.com, and they get a link to buy a product in a WooCommerce store set up with a wordpress site at https://example.com/product/virtual-product
However, this product will be a payment to unlock something on the othersite.example.com site which has its own user and authentication system. (Firebase)
Would it be possible to pass a user id from the othersite.example.com by way of a url query parameter and then have that included in the order info?
ie. From the othersite.example.com someone could be given a link to the product like this https://example.com/product/virtual-product?userid=00000000000000000, with 00000000000000000 being their user id at othersite.example.com.
Then if that userid query value could be included in the order, the following steps should be doable.
Step #2: Have a webhook that fires when the product is purchased, telling a server managing the users for othersite.example.com that the user with userid 00000000000000000 has made a successful purchase of that product.
Is there a way to accept custom values like this to the order? Or is this totally out of the scope of WooCommerce's functionality?
Thanks so much.
I believe that it can be done by using a redirection/link directly to the checkout page, like: "http://yourdomain.com/checkout/?add-to-cart=PRODUCTID&000000" (tested)
In the example, "checkout" stands for the name of your checkout page, "PRODUCTID" stands for the id of desired product, "000000" stands for the user id of redirected person in the other website.
Then you can add a hidden input field to the checkout page (into checkout form, so you will see this value in order) and using the URL you can assign the "000000" (user id) to the value of this field.
I hope that works. If you have any problems with implementation, you can ask me.
- Useful link for hidden input field addition: https://stackoverflow.com/a/42614905/11003615
- Useful link for getting value from current URL using JS: https://web-design-weekly.com/snippets/get-url-with-javascript/
- Useful link for getting value from current URL using PHP/Wordpress Core: https://wordpress.stackexchange.com/questions/274569/how-to-get-url-of-current-page-displayed
- Useful link (contains 4 parts) for adding a custom field to checkout & validating this field & saving this field to order fields & displaying the value of this field in order page: https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-7

How to extract the specific AdWord keyword that a client clicked on?

I'm using AdWords to help generate form submissions, and a form submission is my heuristic for a conversion.
I want to fetch the specific AdWords keyword that generated a conversion and submit it along with the form so that I can track which keyword are generating which submissions. Is this possible?
I don't see an cookie that relates to a Google Ad click, and the automatically appended gclid only contains a timestamp when decoded.
If you are using autotagging in Adwords then you will not get the keyword in realtime to send it along with the form.
You would either need to use manual tagging, and extract the value from the utm_term parameter, or configure valuetrack parameters to have the keyword/matchtype in your destinantion url.
In both cases you'd need to store the value from the query parameter (e.g. in a cookie), read it in the page with the form and append a hidden form field to your form that is set to the proper value.

FOSUserBundle registration form overridden - validation problems

I've modified my registration form and added a few fields (such as First name, Last name, and Organisation name).
My application will have 2 types of users - "regular" users, that will have to provide their First name and Last name, and also "organisations", that will have to provide their organisation name.
When the form is rendered, the system detects the user's "type" and only shows the form fields relevant to that user (for example: "organisations" don't get the First name and Last name fields).
The registration works fine, but there are no validation messages shown... Even if there is an error, it is not displayed.
How should I handle this?
I think it would be a better idea for you to instanciate a different form for different user level, instead of doing that in templating.
Use this:
parent::buildForm($builder, $options);
where you extend your form.

asp.net 1.1 duplicated submission entries

I've got an old framework 1.1 project with the following problem: if user submits a page then in database duplicated records might appear. This error repeats often but is not consistent: in most cases there are no duplicated entries but in some cases there can be upto 4 of them. We disable submit button with JavaScript after first submission.
May be this would be helpful: there is a session object used to store user inputs (which are submitted).
Any scenarios you can think of why duplicated records can happen?
Many thanks
Finally I found that some mobile browsers ignored JavaScript that disabled submission button and users managed to resubmit form multiple times.
The easiest (?) solution to this is the following:
Create a table "SubmissionTokens" in database with two fields: Token (uniqueidentifier), DateCreated (DateTime). Then, when page with submission form loads, add a token to database and save "id" value in a hidden field on the same page. When user submits the form then read token from the hidden field and see if token exists in table SubmissionTokens. If it does exist then insert a new record with form data in the database and delete the token from SubmissionTokens. You can also use DateCreate field to expire tokens.
At work I implemented a bit different solution and just look for duplicated records in the database before inserting a new record. But this is because there is a specific requirement that user must be able to resubmit form if he clicks "back" in browser. In this case the SubmissionToken is already deleted and the first solution wouldn't work.

Resources