I have a post php form and a set of inputs:
- Your Name
- Your Last Name
- My Name
Every input looks the same, only the names change:
<input type="text" name="your_name" value="<?php echo get_option('your_name'); ?>" />
How to set default values when value= is not available?
[edit]
Ok, so, normally I'd do something like:
<input type="text" name="your_name" value="Mike" />
But in this case I have a PHP script that grabs inputs data and displays it using value="<?php echo get_option('your_name'); ?>"
. So I have no idea how to force my form to display "Mike" in my input.
You could use my tiny library ValueResolver in this case, for example:
and don't forget to use namespace
use LapaLabs\ValueResolver\Resolver\ValueResolver;
There are also ability to typecasting, for example if your variable's value should be
integer
, so use this:Check the docs for more examples
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
where your forms are it would be:
then I would have a seperate file on the root level called "default_text.php."
Since
value
is the default, just add a condition around yourget_option
-function, maybe something like this: