My b2evolution Version: 2.x
I have a plugin that makes a couple of form fields. Yay. I discovered that when I edit a post and do something bad in the post b2evo will throw it back at me in edit mode with a message div saying what is wrong, and, will wipe out the content of my custom fields.
In AdminDisplayItemFormFieldset in the plugin I use this to tell my form fields if I am editing a post or not:
$get_post_id = isset($_GET['p']) ? $_GET['p'] : 0;
if( $get_post_id != 0 ) {
If I have an ID then I do a query and get the content for the fields, else I set them to default values (which are mostly empty).
$this->field_content = $query_results['field_content'];
Okay so far so good. The problem happens when I edit a post (and possibly/probably when I create a new post with stuff that b2evo doesn't like. For example adding
<div class="foo
will trigger an error message. A red box with pale red background and red text shows the error, and the background of the textarea for posting is also pale red.
And all the custom field content is gone :(
I'm pretty sure what's happening is I don't see the ID number because for some reason the address bar is bare naked. Or at least free of any parameters is what I mean.
I tried getting rid of the "else" portion of the "if you have a post ID get the info else use blanks as defaults" hoping that $this->field_content would still be valid, but it didn't work.
I guess what I need to do is make that be more complicated, but I'm not sure where to start. Something like this maybe?
if( $get_post_id != 0 ) {
do a query to get current info
} else {
* figure out if we are coming from an error
* if so then figure out how to know the post ID and query it again
} else {
must be new so use defaults
}
Or something like that. So! Does anyone know how my AdminDisplayItemFormFieldset can know if we are coming from an error when attempting to save? Or maybe there is a much better way to find out if we are editing than using isset($_GET['p'])?
Try this