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.

My first plugin attempt with basic PHP skills and a bunch of WordPress experience... What I want:

User fills out form - form action sends them off to a specialized gateway (got that part ok) Select data from the form is saved to a custom table

This is going to probably sound stupid but i think i have all the elements I am just missing how to put them together... This is a very basic example of what I want to expand on later.

This is the function (the stuff that makes the table etc already happens earlier)

function rchs_add_donor() {
   global $wpdb;
   $welcome_name = $_POST['name'];
   $welcome_text = $_POST['text'];

   $rows_affected = $wpdb->insert( play_donors, 
        array( 
                'time' => current_time('mysql'), 
                'name' => $welcome_name, 
                'text' => $welcome_text ) );
}

Now the silly part - how/where do i put the form to utilize this function?

I tested the above with straightforward data instead of variables from the $_POST and that writes to the new table fine.

If anyone could point me in the right direction that would be great!

Did more research based on the first answer came up with this: but need to make sure it is 'correct' and 'secure' seems like i should be sanitizing data or something before writing it to the dbase?

add_shortcode('donor_form_sc','donor_form');
function donor_form(){
global $wpdb;

echo '<form method="post" action="' . $this_page .'">
  <label for="name" id="name">Name: </label>
<input type="text" name="name" id="name" />
<label for="text" id="text">Text: </label>
<input type="text" name="text" id="text" />

<input type="submit" />
  </form>';

  };
 $welcome_name = $_POST['name'];
   $welcome_text = $_POST['text'];
    $rows_affected = $wpdb->insert( play_donors, 
        array( 
                'time' => current_time('mysql'), 
                'name' => $welcome_name, 
                'text' => $welcome_text ) );

It writes to the dbase as expected.

share|improve this question
add comment

1 Answer

Do you mean how you can display the form on your website? If so, write a shortcode for it :) http://codex.wordpress.org/Shortcode_API

Edit: Oh and you might want to add a hook so your function that saves the data is triggered. add_action('init','rchs_add_donor') should do. And add a check in your function to check if your POST is set.

share|improve this answer
    
Ok - added the action... but confused about the rest of it - If I place if (isset($_POST['submit']) { in the function it white screens me. And a shortcode - what I build my form in the shortcode and then call it in my page? –  Ann Jun 12 '13 at 22:59
    
Be sure to prefix your $_POST variables to prevent another plugin or WordPress itself from trying to process your form variables. Example: $_POST['rchs_submit'], $_POST['rchs_name'], etc. –  Rachel Baker Jun 13 '13 at 2:08
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.