1.1.4 • Published 3 months ago

react-gravity-form v1.1.4

Weekly downloads
540
License
ISC
Repository
bitbucket
Last release
3 months ago

React Gravityform

Version

This module includes a react component for dropping Gravity Forms from your Wordpress site into your react applications. If you are considering using this package please use the new next-gravity-forms package since this one will be deprecated in the near feature.

Installation

$ npm install --save react-gravity-form

testing

see the testing readme here

Backend

Make sure to create a custom GF endpoint to fetch the form. See example

Usage

The GravityForm Component

Import component:

import GravityForm from "react-gravity-form";

Include the component anywhere inside your own components:

<GravityForm
	backendUrl="https://www.example.com/wp-json/glamrock/v1/gf/forms/1"
	formID="1"
	onChange={someFunction} // optional - keep all entered values as parameter
	onSubmitSuccess={someFunction} // optional - calls after form has been submitted successfully
	onError={handlerFunction} // optional - fires on GF error (gform_validation hook)
	styledComponents={{Button, Loading, Input...}} // optional
	populatedFields={{parameterName: "Value"}}
	jumpToConfirmation={false} // optional, default is equal to true
	submitComponent={Component} // optional - pass your <Component/> (like loading, another button...) to render in front of the submit button
	getParams={{}} // optional - pass an Object with your params to send the GF request with query string included
/>

Custom component

import ComponentName from 'ComponentName';

...

<GravityForm
  ...
  customComponents={{
    3: ComponentName,
  }}
/>

File upload - Dropzone

  • To use a dropzone inside your file upload field you have to add a dropzone class name in an Appearance tab of the field
  • To change the dropzone text pass it as a prop:
<GravityForm dropzoneText="Drag here or browse to upload" {...props} />

DatePicker

If Date Input Type is datepicker we use a React DatePicker module. If you want to pass your own props to the component use gform_pre_render hook and pass this options using datepickerOptions key. Example:

<?php
add_filter( 'gform_pre_render', 'adjust_date_field' );
function adjust_date_field($form){
	foreach( $form['fields'] as &$field )  {
					if ( $field->type == 'date' ) {
						$field['datepickerOptions'] = array(
          		'minDate' => date("Y/m/d"),
							'dateFormat' => 'MM/dd/yyy'
        		);
					}
	}
	return $form;
}

The Date Picker functionality in our form utilizes the react-datepicker package. Please note that this package does not include default styles. To ensure proper styling of the date picker, you must either provide your own custom styles or import the default styles from the package. To use the default styles, include the following import statement in your code:

import "react-datepicker/dist/react-datepicker.css";

Captcha

We use recaptcha package To make it work pass sitekey as property to GravityForm component

confirmation redirects

When you configure a confirmation redirect to a url or page GF will redirect the submission api call to that page thus causing the submission to fail. you can fix this by adding the following snippit to your wordpress theme.

add_filter( 'rest_post_dispatch', function ( $response, $server, $request ) {
    if ( $response->get_status() !== 200
         || $request->get_method() !== 'POST'
         || empty( $request['form_id'] )
         || $request->get_route() !== "/gf/v2/forms/{$request['form_id']}/submissions"
    ) {
        return $response;
    }
 
    $headers = $response->get_headers();
    unset( $headers['Location'] );
    $response->set_headers( $headers );
 
    return $response;
}, 10, 3 );

Change validation messages from backend

Y

<?php
add_filter( 'gform_pre_render', 'change_error_messages' );
function change_error_messages( $form ) {

		function setErrorMsg($fields, $customMessage) {
			$errorMgs = [
							'custom' => $customMessage,
							'required' => esc_html__('This field is required', 'gravityforms')
			];

			if($fields === 'required') {
				return $errorMgs;
			} else {
				$data = [];
				foreach ($fields as $fieldName) {
					$data[$fieldName] = $fieldName === 'mismatch' ? esc_html__('Mismatch', 'gravityforms') : esc_html__('Enter a valid ' . $fieldName, 'gravityforms');
				}
				return array_merge($errorMgs, $data);
			}
		}

		foreach( $form['fields'] as &$field )  {
			switch ($field['type']) {
				case 'date':
					$field['errorMessage'] = setErrorMsg(['date', 'month', 'year'], $field['errorMessage']);
					break;
				case 'email':
					$field['errorMessage'] = setErrorMsg(['email', 'mismatch'], $field['errorMessage']);
					break;
				default:
					$field['errorMessage'] = setErrorMsg('required',  $field['errorMessage']);
			}
		}
		return $form;
	}

Roadmap

  • Extended the validation functionality with validating attribute values (for example min and max amounts.
  • Allow fields to be prepopulated
1.1.4

3 months ago

1.1.3

3 months ago

1.1.1

3 months ago

1.1.0

3 months ago

1.1.2

3 months ago

1.0.39

4 months ago

1.0.38

4 months ago

1.0.37

4 months ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.34

2 years ago

1.0.22

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.19

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.12

2 years ago

1.0.11

3 years ago

1.0.10

3 years ago

0.0.160

3 years ago

0.0.159

3 years ago

0.0.158

3 years ago

0.0.157

3 years ago

0.0.156

3 years ago

0.0.155

3 years ago

0.0.154

3 years ago

0.0.153

3 years ago

1.0.9

3 years ago

0.0.152

3 years ago

0.0.151

3 years ago

1.0.8

3 years ago

0.0.150

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

0.0.149

3 years ago

0.0.148

3 years ago

0.0.147

3 years ago

1.0.4-alpha.1

3 years ago

1.0.4-alpha.2

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.145

4 years ago

0.0.144

4 years ago

0.0.143

4 years ago

0.0.142

4 years ago

0.0.141

4 years ago

0.0.140

4 years ago

0.0.139

4 years ago

0.0.138

4 years ago

0.0.137

4 years ago

0.0.136

4 years ago

0.0.135

4 years ago

0.0.134

4 years ago

0.0.133

4 years ago

0.0.132

4 years ago

0.0.131

4 years ago

0.0.130

4 years ago

0.0.129

4 years ago

0.0.128

4 years ago

0.0.127

4 years ago

0.0.126

4 years ago

0.0.125

4 years ago

0.0.124

4 years ago

0.0.123

4 years ago

0.0.122

4 years ago

0.0.120

4 years ago

0.0.121

4 years ago

0.0.119

4 years ago

0.0.117

4 years ago

0.0.116

4 years ago

0.0.115

4 years ago

0.0.118

4 years ago

0.0.114

4 years ago

0.0.113

4 years ago

0.0.112

4 years ago

0.0.111

4 years ago

0.0.110

4 years ago

0.0.109

4 years ago

0.0.108

4 years ago

0.0.107

4 years ago

0.0.106

4 years ago

0.0.105

4 years ago

0.0.104

4 years ago

0.0.103

4 years ago

0.0.102

4 years ago

0.0.101

4 years ago

0.0.100

4 years ago

0.0.97

4 years ago

0.0.98

4 years ago

0.0.99

4 years ago

0.0.95

4 years ago

0.0.96

4 years ago

0.0.94

4 years ago

0.0.92

4 years ago

0.0.93

4 years ago

0.0.90

4 years ago

0.0.91

4 years ago

0.0.89

4 years ago

0.0.88

4 years ago

0.0.87

4 years ago

0.0.86

4 years ago

0.0.85

4 years ago

0.0.83

4 years ago

0.0.82

4 years ago

0.0.81

4 years ago

0.0.80

4 years ago

0.0.79

4 years ago

0.0.78

4 years ago

0.0.77

4 years ago

0.0.76

4 years ago

0.0.75

4 years ago

0.0.74

4 years ago

0.0.73

4 years ago

0.0.72

4 years ago

0.0.71

4 years ago

0.0.70

4 years ago

0.0.69

4 years ago

0.0.68

4 years ago

0.0.64

4 years ago

0.0.65

4 years ago

0.0.66

4 years ago

0.0.67

4 years ago

0.0.63

4 years ago

0.0.62

4 years ago

0.0.60

4 years ago

0.0.61

4 years ago

0.0.59

4 years ago

0.0.58

4 years ago

0.0.57

4 years ago

0.0.56

4 years ago

0.0.55

4 years ago

0.0.53

4 years ago

0.0.54

4 years ago

0.0.52

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.47

4 years ago

0.0.48

4 years ago

0.0.45

4 years ago

0.0.46

4 years ago

0.0.44

4 years ago

0.0.43

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.38

4 years ago

0.0.39

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.31

5 years ago

0.0.30

5 years ago

0.0.29

5 years ago

0.0.28

5 years ago

0.0.27

5 years ago

0.0.26

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago