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.

I am trying to make a private form to submit data into an external database so that I can later pull from the database and display the records on a page. So far I have been trying to create a plugin that allows me to fill out the form in wp-admin but when I try to post the data to a different page to store the data I get a "You do not have sufficient permissions to access this page." error.

I am basically trying to create an inventory management system to show products on multiple sites that I own.

For any further questions that may help me find a solutions, I will try to respond asap. Thank you for any help you can provide.

Here is an example of what I am trying to do in code

<?php
add_action('admin_menu', function() {
add_options_page('Add an Item', 'Add an Item', 'administrator', __FILE__, function() {
?>
    <div class="wrap">
    <form action="http://some/url/additem.php" method="POST">
        <input type="text" value="nothing" />
        <input type="text" value="nothing" />
        <input type="submit" value="Send" />
    </form>
    </div>
)};
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Does the code that imports to the external DB need to be on a different page? Adding a conditional that checks if the form is submitted, to your callback function would work as well.

Then your form posts the data back to itself, checks if the form is submited and runs the import script instead of displaying the form.

That way you wont get the permissions error.

add_action('admin_menu', function() {
add_options_page('Add an Item', 'Add an Item', 'administrator', __FILE__, function() {

if(isset($_POST['submit']) && $_POST['submit'] == 'Send'){
    import_items();
}else
    add_item_form();
)};

function add_item_form(){
    <div class="wrap">
    <form method="POST">
        <input type="text" value="nothing" />
        <input type="text" value="nothing" />
        <input name="submit" type="submit" value="Send" />
    </form>
    </div>
}

function import_items(){

    //Your code from http://some/url/additem.php for importing items to the external DB goes here.

}
share|improve this answer
    
+1 No it doesn't have to be on a different page. Thank you for your answer, I will try this right now and see if it works! –  Tangy Aug 22 '13 at 7:24
    
No problem, but please take a look at the code snippet again, I just made an edit. the submit button needs (name="submit") in order for you to be able to access it with ($_POST['submit']) –  Warwick Aug 22 '13 at 7:27
    
There was some syntax I had to fix up, and it still doesn't work but it's definitely a step in the right direction I think. I will take another crack at it and if I have more issues I'll make another question. Thanks again. –  Tangy Aug 22 '13 at 7:46
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.