开发者

Keep data from dissapearing when user submits webform incorrectly

I am using Wordpress, and a contact form plugin, but it's still php, anyway, it's kind of a long form, and the client wants the data to stay if the user doesn't fill it out correctly and has to come back to the page. As it is now, they have to refill everything. I know there is jquery that will handle this, but I don开发者_运维知识库't know if I can use it in this plugin.


Unfortunately there is no magic. but will you can do something like this:

   <?php

function get_field_value($field_name, $method = 'POST') {
    $method = strtoupper($method);
    if ($method == 'POST') {
        if (isset($_POST[$field_name]))
            return $_POST[$field_name];
    }
    elseif ($method == 'GET') {
        if (isset($_GET[$field_name]))
            return $_GET[$field_name];
    }
    else {
        return 'ERROR: invalid method';
    }
   return '';
}

?>

And in your HTML you will have:

<input name="example><?php echo $get_field_value('example','GET'); ?></input>

of course my code is not the best in the world but it will give you the idea of how to go with it.

Good Luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜