WordPress.org

Ready to get started?Download WordPress

Forums

Inserting text into form fields. (8 posts)

  1. andrewbird
    Member
    Posted 2 years ago #

    Hi all,
    I wish to insert text into a form field. Is there a filter I can use to alter the text entered in a form field when the page loads?

    E.G. If for example, you had a custom field in a post, and you wanted the field to be populated with a random text string on page load, how could you do that. I actually want to populate it with the result of a function, but that is beside the point. It is important that the user can delete and retype if they wish.

    Many thanks,
    Andrew

  2. wspencer
    Member
    Posted 2 years ago #

    Are you looking for the custom field to just contain a default string? Even if that string is the result of a different function?

    If you can be more specific about what you're looking for, I'm pretty sure I can help you out.

  3. andrewbird
    Member
    Posted 2 years ago #

    No. I have a text feild in a custom metabox, and a button in that box. Together they submit via action = "" a text string to a php function which reads some xml. I wish to complete some form fields based on the results of the function.
    So say my function returns $var1 and $var2, I need to put those variable strings into, lets say, a custom taxonomy field. So i was looking for the hook that is called when those input fields are printed.... is that the correct of incorrect way to deal with this problem.

    Many thanks.
    Andrew

  4. andrewbird
    Member
    Posted 2 years ago #

    Sorry to bring this up, but I have not yet solved this. Anyone any ideas, or alternative methods.

    Many thanks,
    Andrew.

  5. bcworkz
    Member
    Posted 2 years ago #

    Modify your page template to call your function from inside your form field. Roughly like this:
    <textarea><?php echo get_my_data(); ?></textarea>

  6. andrewbird
    Member
    Posted 2 years ago #

    which page template, I want to do this via a plugin, so I need a function in the plugin to do this. I'm suprised more people are not trying to do things like this to be honest.

  7. bcworkz
    Member
    Posted 2 years ago #

    Where ever the form is being defined. This is really a theme based solution.

    A plugin could use javascript to insert text via innerHTML, your php code would prepare the needed data and javascript, assemble it all into a script block, and then echo it all into the page head via the wp_head action.

  8. andrewbird
    Member
    Posted 2 years ago #

    For anyone else reading, the above is not the way to insert script blocks into your WP. Thanks for the help though.

Topic Closed

This topic has been closed to new replies.

About this Topic