• Resolved edtiley

    (@edtiley)


    I’m building an OOP plugin to create admin pages to be used by a Multisite superadmin that uses a custom table. It’s a simple routine. Pick a record from a dropdown list, then get all the field data and display a second form to edit those fields.

    Since there seems to be no way to call a class method in the action = part of the form tag, I’ve written a function that uses action = ” so the page will call itself on submit. The method is POST

    Here’s the logic:

    if($_POST['form_two'] !== 'save_data' ){
       global $wpdb ;
       //do a query, get some values create a form to
       // let the user select one from a dropdown
       echo '<form type="post" action="" id="select_one" name "select_one">';
       // a foreach to populate and display the <select> element
       echo '<input type="hidden" name="form_two" id="form_two" value="save_data"/>';
       echo '<input name="send_select" id="send_select" type="submit" value="Select Ad To Edit" />';
       echo '</form>';
    } else {
    // the code for the edit form
    }

    Fails every time. But change _POST to $_REQUEST and it works perfectly. You get an ungainly URL when you use REQUEST, which seems a bit odd too, but it works great.

    I just want to know why $_POST doesn’t get populated but $_REQUEST does. It took me a LONG LONG time to figure out this hack. I’ just like to gain a little knowlege for the effort.

    Thanks,

    Ed

Viewing 3 replies - 1 through 3 (of 3 total)
  • $_REQUEST can be used to reference both GET and POST data. It is usually used when you can’t be sure which method data will be submitted with.

    Since $_POST doesn’t work your form is probably defaulting to the GET method. You could add method="post" to your form if you want to force it to use the POST method.

    Thread Starter edtiley

    (@edtiley)

    Curtis,

    > You could add method=”post”

    Dayum!!!

    I just looked at that code above and saw it!

    <form type='post'> // Yeah, that works NOT!

    Sheesh, do I feel stupid. Perhaps I should change type to method huh?

    Thank you, sir. Sometimes it just takes another pair of eyes to open your own.

    Ed

    (Also a DC area transplant living in Florida)

    Thread Starter edtiley

    (@edtiley)

    Cirtis,

    PS — I just looked back at the form that creates the record in another method of the class, and that’s where the error started thanks to cut and paste.

    Somehow though jQuery and AJAX covered that sin (type = ‘post’) because it picked up the proper values, then POSTed them when calling the callback function.

    Sheesh!

    Thanks again!

    Ed

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Why does $_REQUEST work but not $_POST’ is closed to new replies.