The MU forums have moved to WordPress.org

Populate a form (11 posts)

  1. realsol
    Member
    Posted 15 years ago #

    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.

  2. realsol
    Member
    Posted 15 years ago #

    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.

  3. realsol
    Member
    Posted 15 years ago #

    Ok. Here is what I tried:


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

    After running the code, I am 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?

    Anyone?

  4. realsol
    Member
    Posted 15 years ago #

    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.

  5. dsader
    Member
    Posted 15 years ago #

    See note on get_the_content vs. the_content:

    $content = apply_filters('the_content', $content);

    But why not simply?$content = the_content();

    Using urlencode to html_entity_decode?

    http://ca3.php.net/manual/en/function.htmlspecialchars.php
    http://codex.wordpress.org/Function_Reference/wpautop

  6. realsol
    Member
    Posted 15 years ago #

    Thanks. I'll take a look. Don't know if it makes a difference or not, but I am getting the contents from add_filter('the_content', 'myrecipe_filter_post');

    When I examine the line, it contains ascii characters for line feeds, which is what I want to have when I fill in the form. But when I fill in the form (it is a standard multi edit field in a standard html form, the <p>'s and
    's
    automatically replace the line feeds that wordpress gives me in the content.

    This only happens if I display the form on a wordpress page. If I display the form in blank page, outside of wordpress, and fill the form the same way, the <p>'s and
    's
    do not be inserted.

    I know it might be confusing, but I am sure someone that has worked with populating forms inside a wordpress page has ran into this also.

    I'll take a look at the above references for hints.

  7. realsol
    Member
    Posted 15 years ago #

    OK. From my reading, it looks like wpautop is the problem. At least I am guessing, since the paragraph tags and line break tags only get inserted if the form is displayed on a WordPress page.

    Like I said, it is populated properly when outside of Wordpress.

    I have seen some Form Plugins that don't have the tags embedded in default form text, but looking at one of them, TDO mini forms, I can't see why it displays default text without the tags being embedded.

    Still, any other idea's. I know someone has had this problem before.

    Thanks again.

  8. dsader
    Member
    Posted 15 years ago #

    You mean apply_filter('the_content', 'myrecipe_filter_post'); ?

  9. realsol
    Member
    Posted 15 years ago #

    No, this is being run as a plugin. I am hooking into the 'the_content' filter using add_filter('the_content', 'myrecipe_filter_post'), so I am getting the content straight from WordPress.

    Like I said, WordPress is not giving me any tags, but straight line feed's. I didn't see them at first until I used php's ord() on each character in the string and found the line feeds. At first I was trying to just strip them out, since I figured they were in there because they show as if they are when echo'ed back out. But after strpos() failed finding them, i dug deeper with ord() to find the actual #10 character was being returned.

    My problem is when I try to set the default text in the edit box to the string, I then get the tags displayed. This only happens in WordPress pages. If the form is populated outside of WordPress, the form doesn't show any tags. I believe this is due to the wpautop running at the last minute before displaying the form.

    I need to populate the form in a WordPress page that doesn't convert the linefeed ASCII character (#10) to <code
    and double line feeds to <p>'s and </p>'s . There has to be a way to do this. Right?

  10. realsol
    Member
    Posted 15 years ago #

    OK. Got it to work. But I don't know how, :).

    I was playing around with the the apply_filters(). I looked over you links and also opened up some code for TDO mini forms. I noticed it too was using apply_filters() but in this manner, $content_content = wp_filter_post_kses($content_content), where $content_content was their content they read. They also used apply_filters('the_content', strip_tags($content_content,$options['allowable-tags']).

    So, I tried to apply this to my content that I just read like $direction .= apply_filters('the_content', $direction). Well, this just added the correct formatting I was looking for but keeping my old tagged formating. I guess .= adds to the variable. Didn't know about the .=. Can you tell I am new to all of this.

    Anyhow, I noticed that other portions of my form had their tags stripped, even though I only applied it to the $directions variable. So I started to wonder, and added this to my code.

    $my_post = get_post($_REQUEST['recipe_id']);
    apply_filters('the_content', $my_post->post_content);

    This seemed to strip out all of the tags from my form. Not real sure why since I didn't apply it to a variable. It is my guess, since I am in the loop that when you use apply_filters() it applies it to all of the content withing the current post you are in, thus stripping out my tags within my form.

    Am I right?

    I mean I am glad it is working, though I would like to understand why.

    Thanks again for pointing me in the right directions.

  11. realsol
    Member
    Posted 15 years ago #

    Oh, and I was wrong, I am calling php code from within my page, not within the loop with add_filter('the_content', 'myrecipe_filter_post'). 2 separate files. The one in the loop does the formatting of the recipe card, the one that fills the form is called within the page itself. Sorry 'bout that.

About this Topic