Question

Well the question is pretty clear. How could i use text from a placeholder e.g from the below text. I've been searching a lot for this and haven't found a solution. Your help would be appreciated.

<input type="text" placeholder="YYYY, MM - 1, DD" name="director_date"
 value="<?php print get_option('director_date');
 ?>" />
Was it helpful?

Solution

For a non javascript solution, you'll have to test for an empty field on form submittal.

<?php
if(empty($_REQUEST['director_date']))
{
    $dir_date = "YYYY, MM - 1, DD"; //Set desired date here.
} else {
    $dir_date = $_REQUEST['director_date'];
}

OTHER TIPS

My first thought was to use javascript. However, you should use ajax or something to send it to the server.

function getMe(){
  var input = document.getElementsByTagName('input');
  var final = [];
  for(var i = 0; i<input.length;i++){
  if(input[i] == ''){
       final[input[i].name] = input[i].placeholder;
    } else {
       final[input[i].name] = input[i].value;
    }
  }
}

Use your "placeholder" as the input's default value, then throw in some javascript to clear the value on focus and restore it on blur if empty.

<input type="text" onfocus="if(this.value=='placeholder text') this.value='';" onblur="if(this.value=='') this.value='placeholder text';" value="placeholder text">

JSFiddle demo

You could do something like this

$('form').submit(function(){
    var input = $(this).find('input[name=box]');
    if(input.val() == ""){
       input.val(input.attr('placeholder'));       
    };
});

DEMO FIDDLE (ignore the alert and return false): http://jsfiddle.net/TwY3E/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top