Title: Inserting text into form fields.
Last modified: August 20, 2016

---

# Inserting text into form fields.

 *  [andrewbird](https://wordpress.org/support/users/andrewbird/)
 * (@andrewbird)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/)
 * 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)

 *  [wspencer](https://wordpress.org/support/users/wspencer/)
 * (@wspencer)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698498)
 * 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](https://wordpress.org/support/users/andrewbird/)
 * (@andrewbird)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698505)
 * 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](https://wordpress.org/support/users/andrewbird/)
 * (@andrewbird)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698717)
 * Sorry to bring this up, but I have not yet solved this. Anyone any ideas, or 
   alternative methods.
 * Many thanks,
    Andrew.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698718)
 * 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](https://wordpress.org/support/users/andrewbird/)
 * (@andrewbird)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698734)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698735)
 * 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](https://wordpress.org/support/users/andrewbird/)
 * (@andrewbird)
 * [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698739)
 * 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.

## Tags

 * [filter](https://wordpress.org/support/topic-tag/filter/)
 * [form](https://wordpress.org/support/topic-tag/form/)
 * [hook](https://wordpress.org/support/topic-tag/hook/)
 * [input](https://wordpress.org/support/topic-tag/input/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 7 replies
 * 3 participants
 * Last reply from: [andrewbird](https://wordpress.org/support/users/andrewbird/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/inserting-text-into-form-fields/#post-2698739)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
