Created
June 24, 2021 13:56
-
-
Save girafffee/175a1c13a70d3a52aeb0600154a6fc02 to your computer and use it in GitHub Desktop.
How to set JetFormBuilder form statuses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Jet_Form_Builder\Exceptions\Action_Exception; | |
add_action( 'jet-form-builder/custom-action/test_action', function ( $request, $handler ) { | |
if ( empty( $request['age'] ) ) { | |
/** | |
* You can use one of the default statuses | |
* 'success' => 'Form successfully submitted.', | |
* 'failed' => 'There was an error trying to submit form. Please try again later.', | |
* 'validation_failed' => 'One or more fields have an error. Please check and try again.', | |
* 'captcha_failed' => 'Captcha validation failed', | |
* 'invalid_email' => 'The e-mail address entered is invalid.', | |
* 'empty_field' => 'The field is required.', | |
* 'internal_error' => 'Internal server error. Please try again later.', | |
* 'upload_max_files' => 'Maximum upload files limit is reached.', | |
* 'upload_max_size' => 'Upload max size exceeded.', | |
* 'upload_mime_types' => 'File type is not allowed.', | |
*/ | |
throw new Action_Exception( 'empty_field' ); | |
} | |
if ( absint( $request['age'] ) < 18 ) { | |
throw ( new Action_Exception( 'Your age is less than necessary' ) )->dynamic_error(); | |
} | |
/** | |
* If all checks are passed, you just need to do Nothing, | |
* so that the form would continue its work or successfully complete it. | |
* | |
* In rare cases, you can interrupt the execution of the form with a successful status. | |
*/ | |
if ( 199 === absint( $request['age'] ) ) { | |
// or throw new Action_Exception( 'success' ); | |
throw ( new Action_Exception( 'Lucky!' ) )->dynamic_success(); | |
} | |
}, 10, 2 ); |
reolace curl with:
`
$secret = 'a8333333333331';
$url = 'https://33333333333/api/sendNotification';
$args = array(
'timeout' => 45,
'method' => 'POST',
'body' => array('secret' => $secret, 'message' => 'ФИО: ' . $request['field_name'] . ' Тел: ' . $request['name_phone'] . ' Адр: '. $request['adress'] )
);
$response = wp_remote_post( $url, $args );
`
and noe notify work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I try:
`add_action( 'jet-form-builder/custom-action/m_zayavka_popup', function($request) {
$secret = 'a8******11';
$dataMsg = [
'secret' => $secret,
'message' => 'ФИО: ' . $request['field_name'] . ' Тел: ' . $request['name_phone'] . ' Адреса: '. $request['adress']
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://bot.******/api/sendNotification',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($dataMsg)
]);
curl_exec($curl);
curl_close( $curl );
}
);`
all ok, action email – work\send, action hook – work, but “Form successfully submitted” – not working…. message not showed….
Any tips?