Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
  1. How do I add a custom form to a WordPress page? I do not need contact form I need a custom form that has my own fields. Some fields get data from a database table like cities and country or any other dependable fields.

  2. How can I make a form to save data from a user to user meta fields that I created in the dashboard area?

I found a plugin that works as form manager, but it's not free. I tried using cform and didnt know how to get access to posted data from the form.

share|improve this question
add comment

1 Answer

A basic example of inserting data into post meta fields.

In your chosen template file you can do something similar to,

<?php   
//this does not include data validation and sensitization but will check for the
//existence of $_POST values being set. 

if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "add_meta") {

if (isset ($_POST['post_id']) ) {
    $post_id    = $_POST['post_id'];
} else {
    echo 'Enter a post ID';
}

if (isset ($_POST['meta_key']) ) {
    $meta_key   = $_POST['meta_key'];
} else {
    echo 'Enter a meta key';
}

if (isset ($_POST['meta_value']) ) {
    $meta_value = $_POST['meta_key'];
} else {
    echo 'Enter a meta value';
}
    update_post_meta($post_id, $meta_key, $meta_value);

}

?>

Form HTML

<form name="add_meta" action="" "method="POST">
<input type="text" name="post_id" value="" />
<input type="text" name="meta_key" value="" />
<input type="text" name="meta_value" value="" />
<input type="submit" name="submit" value="Submit" />
</form>

I highly recommend you read about Data Validation and Sensitization on the WordPress Codex followed by this good tutorial at WPTuts by Stephen Harris

This is only a starting point, you need to make the effort and show us what further research you have done, what code you are trying/writing and provide a detailed explanation of what problems you are facing to receive further help.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.