• 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

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    Thread Starter andrewbird

    (@andrewbird)

    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

    Thread Starter andrewbird

    (@andrewbird)

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

    Many thanks,
    Andrew.

    Moderator bcworkz

    (@bcworkz)

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

    Thread Starter andrewbird

    (@andrewbird)

    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.

    Moderator bcworkz

    (@bcworkz)

    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.

    Thread Starter andrewbird

    (@andrewbird)

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Inserting text into form fields.’ is closed to new replies.