Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
react-gravity-form
Advanced tools
A component for including Gravity Forms on React apps via the Wordpress API
This module includes a react component for dropping Gravity Forms from your Wordpress site into your react applications.
$ npm install --save react-gravity-form
Make sure to create a custom GF endpoint to fetch the form. See example
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
/>
import ComponentName from 'ComponentName';
...
<GravityForm
...
customComponents={{
3: ComponentName,
}}
/>
dropzone
class name in an Appearance tab of the field<GravityForm dropzoneText="Drag here or browse to upload" {...props} />
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;
}
We use recaptcha package
To make it work pass sitekey
as property to GravityForm component
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;
}
FAQs
A component for including Gravity Forms on React apps via the Wordpress API
We found that react-gravity-form demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.