HTML/PHP - default input value
You need to check the return of get_option first, and substitute something if a default is not available
<?php $default = get_option('your_name'); if( $default == "") { $default = <whatever your default value is>; }?><input type="text" name="your_name" value="<?php echo $default; ?>" />
Change get_option to return an empty string (or something else) if the default is not available.
you can change the get_option()
function to be something like
function get_option($name) { $defaults = array( 'fist_name' => 'Mike', 'fist_name' => 'Wordpressor', 'my_name' => 'Dunno' ); // get the value from the $defaults array $val = $defaults[$name]; // but if the same value has already been posted - replace the default one if (isset($_POST[$name])) { $val = $_POST[$name]; } return $val;}
This is How I solved this issue in my problem which I believe is similar, when $_POST is read the value is populated from the $_POST value else sets a default of Mike
value="<?php if (isset($_POST['name'])) echo $_POST['name']; else echo "Mike"?>" >
Hope this helps someone oneday