WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Function not found (7 posts)

  1. hllawrence
    Member
    Posted 2 years ago #

    Hi all,
    This is my first post here, so please forgive me if I'm missing any common post etiquette. Please feel free to point me towards any post recommendation documents that I might have missed.

    I am creating a new wordpress plugin, and this is the first time I've done this.

    The file I'm working on is just meant to allow the user to manage a list of resources (add, delete, create, and change between Active and Inactive). I had this all working with multiple files (resources.php, resources_delete.php, resources_add.php, etc) but thought it was probably not good programming to have a different file for every action. I am working now on having all of the resources code within one file (resources.php).

    I have created a drop-down box so the user can choose if they want to see active resources or inactive ones. Based on the drop-down box, I want to change the output of the page. When the dropdown is updated, a function called "process()" would be called to display the page based on the input. However, when I click the View button, it says the function is not found.

    Can anyone help? Is there some way that I'm supposed to register the function or am I just out to lunch on my method here?

    <?php 
    
    global $wpdb; 
    
    $ddoutput = $pre_HTML; 
    
    $ddoutput .= "<form action=process($dropdown) method=\"post\" name=\"actorinact\">
    Record Type:
    <select name=\"dropdown\" value=\"options\">
    <option value>Choose an option</option>
    <option value=\"active\">Active</option>
    <option value=\"inactive\">Inactive</option>
    </SELECT>
    
    <INPUT type=\"submit\" value=\"View\">
    
    </form> ";
    
    $ddoutput .= $post_HTML; 
    
    echo $ddoutput;
    
    function process($dropdown)
    {.....

    Thanks very much,
    Heather

  2. bcworkz
    Member
    Posted 2 years ago #

    Don't forget html actions like forms occur on your user's browser, on their remote computer. They cannot directly call php functions that only exist on your server.

    To initiate a php function from a form action, the form sends a PUT or POST request over the internet to a page on your server with the form contents included. Your page, upon receiving such a request, examines the form data, does whatever needs doing, then, (typically) would respond to the client request with additional html to display to the user.

  3. michael.mariart
    Member
    Posted 2 years ago #

    Your code doesn't look like it's doing what you expect it to.

    My first question is... Is the process() function supposed to be PHP or JavaScript? (sorry if this is obvious, but I've seen people get these things wrong many times before)

    If it's PHP, then you can't call it by the forms action like that. The way that you have it set up there, it actually won't be called at all because it's only ever referred to in a string.

    If it's JavaScript, then you have coded it in PHP and not JavaScript, so you need to change that. The process() function that you have is server-side so is never actually seen by the users browser.

  4. hllawrence
    Member
    Posted 2 years ago #

    Hi, thanks for the responses. So far all of my code has been php and html.

    So I guess I would ask, is there a better way I should be doing this? Basically I want to have a page that deals with various database operations on a table, and I'd like to avoid spreading it out across multiple php files. What would be the best practice for this sort of plugin?

    Thanks!
    Heather

  5. hllawrence
    Member
    Posted 2 years ago #

    Maybe I should be doing it in a similar way to my data entry forms?

    if(isset($_POST['newresdesc'])) {...}
    
    if(isset($_POST['delresnum'])) {...}

    Is that what you're referring to bcworkz?

  6. bcworkz
    Member
    Posted 2 years ago #

    I'm not sure I understand what you're suggesting, but it looks like you may be on the right path.

    You don't need multiple pages, but your page needs to know whats being asked of it. For instance, if it's a GET request, you might send out the form to be filled out. If it's a POST request you do something with the form data and send a confirmation or something. Your page can handle requests from different forms if you determine which form you're processing, as what you are suggesting, I think.

    You single page can also serve different forms if it can somehow differentiate which form to serve, perhaps by URL parameters included in the initiating link.

  7. hllawrence
    Member
    Posted 2 years ago #

    Thanks, I think I am getting closer now. I haven't quite got it working yet, but I'm getting pretty close. I will mark this as resolved.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic