-
Notifications
You must be signed in to change notification settings - Fork 572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render Form Fields separately / dynamically on the front end #506
Comments
@jtsternberg hi big thanks for the commits, and I'm sorry for not very clear on my questions. So basically, I've achieved what I wanted to, but with a little copy this and that from the core. <?php
$GLOBALS['getfront_cmb'] = wds_frontend_cmb2_get(); // get the object array
CMB2_hookup::enqueue_cmb_css(); //for the wyswyg, I have to do this manually
CMB2_hookup::enqueue_cmb_js(); //for the wyswyg, I have to do this manually
function getcmb_atts($id, $atts){ // to get only a specific attribute
$that_field = $GLOBALS['getfront_cmb']->meta_box['fields'][$id][$atts];
return $that_field;
}
function getcmb_field($id){ // THIS is the RENDER method, that I copied from the plugin
$that_field = $GLOBALS['getfront_cmb']->meta_box['fields'][$id];
$field = $GLOBALS['getfront_cmb']->get_field( $that_field )->render_field();
return $field;
}
?>
<!-- the form -->
<form class="cmb-form post-form" method="post" id="<?php echo $GLOBALS['getfront_cmb']->cmb_id; ?>" enctype="multipart/form-data" encoding="multipart/form-data">
<input type="hidden" name="object_id" value="<?php echo $GLOBALS['getfront_cmb']->object_id; ?>">
<?php wp_nonce_field( $GLOBALS['getfront_cmb']->nonce(), $GLOBALS['getfront_cmb']->nonce(), false, true ) ?>
<!-- .... whatever bootstrap or foundation or those grids html tags ... -->
<?php getcmb_field("submitted_post_content"); //this is for the wyswyg field ?>
<!-- .... whatever bootstrap or foundation or those grids html tags ... -->
<!-- .... whatever bootstrap or foundation or those grids html tags ... -->
<?php getcmb_field("submitted_post_title"); // text field ?>
<!-- .... whatever bootstrap or foundation or those grids html tags ... -->
<!-- this is the magic of the first function, let's say we want to render a text field (you have to acknowledge the rendered field should be look like first) -->
<input type="text" class="regular-text italic-placeholder" name="submitted_post_title" id="submitted_post_title" placeholder="<?php echo getcmb_atts('submitted_post_title', 'placeholder'); ?>">
<!-- finally the closing form -->
<input type="hidden" name="atts[post_author]" id="atts[post_author]" value="<?php echo get_current_user_id(); ?>">
<input type="hidden" name="atts[post_status]" id="atts[post_status]" value="pending">
<input type="hidden" name="atts[post_type]" id="atts[post_type]" value="post">
<button type="submit" name="submit-cmb" id="submit-cmb" title="Publish" class="hr-btn light-grey">Publish</button>
</form> Is my code above a bad practice or a pretty good one? Hope this helps someone! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Is there any hooks / function to render the form fields individually?
Because when you use cmb2_get_metabox_form, it automatically added the form and the fields in a single call based on cmb2_metabox_form(). I mean is there any function to call like,
You know, it's for the front end templating matters.
Thanks.
The text was updated successfully, but these errors were encountered: