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 can change the
get_option()
function to be something likeSimply use a ternary operator. its pretty easy try this
You need to check the return of get_option first, and substitute something if a default is not available
Change get_option to return an empty string (or something else) if the default is not available.
You can do a switch statement and have default to be whatever you want it to be.
Set some variable at start with the post variables.
like
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
Hope this helps someone oneday