{$strength}";
}
}
public function get_field_label_class(){
return 'gfield_label gfield_label_before_complex';
}
public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {
/**
* A filter to allow the password to be encrypted (default set to false)
*
* @param bool Whether to encrypt the Password field with true or false
* @param array $form The Current Form Object
*/
$encrypt_password = apply_filters( 'gform_encrypt_password', false, $this, $form );
if ( $encrypt_password ) {
$value = GFCommon::openssl_encrypt( $value );
GFFormsModel::set_openssl_encrypted_fields( $lead_id, $this->id );
}
return $value;
}
/**
* @deprecated 2.4.16
*
* @param $entry
* @param $form
*/
public static function delete_passwords( $entry, $form ) {
$password_fields = GFAPI::get_fields_by_type( $form, array( 'password' ) );
$field_ids = array();
$encrypted_fields = GFFormsModel::get_openssl_encrypted_fields( $entry['id'] );
foreach ( $password_fields as $password_field ) {
$field_ids[] = $password_field->id;
GFAPI::update_entry_field( $entry['id'], $password_field->id, '' );
$key = array_search( $password_field->id, $encrypted_fields );
if ( $key !== false ) {
unset( $encrypted_fields[ $key ] );
}
}
if ( empty( $encrypted_fields ) ) {
gform_delete_meta( $entry['id'], '_openssl_encrypted_fields' );
} else {
gform_update_meta( $entry['id'], '_openssl_encrypted_fields', $encrypted_fields );
}
}
/**
* Removes the "for" attribute in the field label.
* Inputs are only allowed one label (a11y) and the inputs already have labels.
*
* @since 2.4
*
* @param array $form The Form Object currently being processed.
*
* @return string
*/
public function get_first_input_id( $form ) {
return $this->is_confirm_input_enabled() ? '' : parent::get_first_input_id( $form );
}
/**
* Determines if the Confirm Password input is enabled.
*
* @since 2.4.15
*
* @return bool
*/
private function is_confirm_input_enabled() {
// Get Confirm Password input.
$confirm_input = GFFormsModel::get_input( $this, $this->id . '.2' );
return isset( $confirm_input['isHidden'] ) ? ! $confirm_input['isHidden'] : true;
}
/**
* Passwords are not saved to the database and won't be available in the runtime $entry object unless we stash and
* rehydrate them into the $entry object after it has been retrieved from the database.
*
* @since 2.4.16
*
* @param $form
*/
public static function stash_passwords( $form ) {
foreach( $form['fields'] as $field ) {
/* @var GF_Field $field */
if ( $field->get_input_type() == 'password' ) {
self::$passwords[ $field->id ] = $field->get_value_submission( rgpost( 'gform_field_values' ) );
}
}
}
/**
* Hydrate the stashed passwords back into the runtime $entry object that has just been saved and retrieved from the
* database.
*
* @since 2.4.16
*
* @param $entry
*
* @return array $entry
*/
public static function hydrate_passwords( $entry ) {
foreach( self::$passwords as $field_id => $password ) {
$entry[ $field_id ] = $password;
}
// Reset passwords so they are not available for the next submission in multi-submission requests (only possible via API).
self::$passwords = array();
return $entry;
}
}
GF_Fields::register( new GF_Field_Password() );