admin管理员组文章数量:1429078
So I am trying to get the current post id when using the gravity forms gform_field_validation
filter.
class WhiteLabel
{
public function __construct()
{
// validate the sub domain
add_filter( 'gform_field_validation_12_12', [$this, 'gf_validate_site_sub_domain'], 10, 4 );
}
public function gf_validate_site_sub_domain($result, $value, $form, $field)
{
// vars
global $wpdb;
$sub_domain = $value;
// attempt to load our sub domain from the database
$site_id = (int)$wpdb->get_var("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='site_sub_domain' AND meta_value = '" . esc_sql($sub_domain) . "'");
// if is valid and site id already exists and is not equal to current post id
if ( $result['is_valid'] && ( $site_id && ($site_id !== get_the_ID() ) ) ) {
// set is valid result as false
$result['is_valid'] = false;
// display error message
$result['message'] = '<a href="https://'.$sub_domain.'domain" target="_blank">'.$sub_domain.'.domain</a> is already in use.';
}
// return result
return $result;
}
}
new WhiteLabel();
So the above code works fine and successfully validates field when form is submitted (first time only).
When the page loads the form for the first time via ajax, this condition below works for the fist time when the form is submitted...
if ( $result['is_valid'] && ( $site_id && ($site_id !== get_the_ID() ) ) )
As you can see above get_the_ID()
is working doing it's thing (first time)
The Problem
But when my form reloads via ajax after the first submission, and then when the form is submitted for a second time, get_the_id()
does not work.
I've tried using..
global $post;
$post->ID
..inside my validation function, but this only works for first submission, and on the second submission it fails, because my error message shows even though my form is on the current post id.
Any help would be hugely appreciated, I wish I could get the $entry
data because that contains my post id.
See docs /
本文标签: phpHow to get current post id in gformfieldvalidation gravity forms
版权声明:本文标题:php - How to get current post id in gform_field_validation gravity forms 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745455644a2659088.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论