• I am creating a plug-in that allows the users to create their own post. I have seen other plug-in’s but they really didn’t do what I was looking for.

    I got the posting down, but am having a problem trying to populate my form to let them edit their posts. When they want to edit the post, I pull the content from get_post and send it to the form they used when creating the post. I am doing this by passing the content as a standard HTTP post. I urlencode it first, since the post content appears to have line feeds, and then populate the form. But I am getting all sorts of encoded char. Like ‘\’ is front of commas, and <br \> tags within the multi line edit box.

    I tried to urldecode the strings when they came in but that didn’t do anything.

    How can I get rid of these before populating the form or is there a better way?

    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter realsol

    (@realsol)

    Anyone.

    I am basically just trying to populate a multi-line form with the contents of a post and not display the
    and <p> but instead just have them displayed to the user as line feed. No need to confuse them.

    Thanks again.

    There’s a lot more you could do to be more accurate with this but for quick and dirty:

    <?php $content = strip_tags(stripslashes(get_the_content())); ?>
    <form action="">
      <textarea name="test" rows="50" cols="65">
        <?php  echo $content; ?>
      </textarea>
    </form>

    Hope that helps.

    Thread Starter realsol

    (@realsol)

    Thanks churchthemer, I’ll give it a shot.

    Thread Starter realsol

    (@realsol)

    OK. After running the code, I was still getting them in the form, but only [p] and [/p]. After running a ord() on the character positions, I found they don’t exist in the string. They must be a line break and the multi-line form is somehow doing some sort of HTML Encoding to the string when it see’s a line break.

    Is there a way to set the HTML multi-line form edit field to not do this, but in turn just display a line feed as a line feed?

    Thanks again.

    Thread Starter realsol

    (@realsol)

    As a side not, when I display the form outside of WordPress, I don’t get the <p> and </p> codes. Only happens in wordpress.

    The real trick here is finding out when and why those p tags are being added. Is wordpress converting line breaks to <p> (seems like it) or is something else happening? You may want to check for those characters and/or remove them by using the the content filter hook.

    If wordpress is converting \n to <p> you may want to search for \n and stip it out of the content instead of <p>.

    Something like this:

    function stripP($string){
        global $wp_query;
        $findthis   = '\n';
        //or $findthis   = '<p>';
        $pos = strpos($content, $findthis);
        if ($pos === false) {
            echo "$findthis not found."
        }
        else {
            //Add remove routine here
            echo "$findthis found.";
        }
    }
    add_filter('the_content', 'stripP');

    You may want to check for more then <p>, like </p> or alternate formattings of those tags. You could add these characters to an array and check/remove them in a for each loop or something.

    Hope that helps.

    Thread Starter realsol

    (@realsol)

    Thanks again for taking the time to reply.

    I figured it out. Never have seen ‘\n’ documented anywhere. Tried to search it on php’s site but they only let your search 3 characters or longer. I finally used ord() against each char in the strings to find that sure enough, there were chr(10) in the the string. And yes, when WP see’s these, it automatically converts on chr(10) to line break and when it see’s 2 it converts it to paragraph tags.

    So it tried this, apply_filters(‘the_content’, $my_post->post_content), where $my_post was the variable holding my post in question. Sure enough, the breaks and paragraph tags disappeared.

    Thanks for all of you help and suggestion that help point me in the right direction.

    Right on man! I’m really glad you got it sorted.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Populate a form’ is closed to new replies.