I have a post php form and a set of inputs:
Every input looks the same, only the names change
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.
Simply use a ternary operator. its pretty easy try this
$default = 'Mike';
$your_name = get_option('your_name');
$condition = !empty($your_name) ? $your_name : $default;
<input type="text" name="your_name" value="<?php echo $condition; ?>" />
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
<input type="text" name="your_name" value="<?php echo empty(get_option('your_name')) ? "TheDefaultValue" : get_option('your_name'); ?>" />
I agree with Teneff but I would break it out.
In the index.php I would have the following at the top of the doc
<?
$defaultText = include 'default_text.php';
?>
where your forms are it would be:
<form method="post" action="">
<input id="names"><? echo $defaultText; ?> </input>
</form>
then I would have a seperate file on the root level called "default_text.php."
<?
$Name = <<<EOD Name EOD;
return $Name;
?>
You can do a switch statement and have default to be whatever you want it to be.