I'm getting a little lost :d
Short explanation:
I want to be able to process $_POST data when a submit button is clicked on a custom post type. So firstly how or what function can I use to add a custom input submit, and secondly how can I build a function for the submitting of this button? Can't seem to find a solution anywhere!
Long explanation:
I'm building a authorisation paypal system for a custom post type named orders. I have my orders in a table which I access using a class. I have my payment information and I know what I have to do which is capture the payment, but I want a button to be able to do this and return errors. So I want a separate button to 'update' and a method of capturing the action so I can do my API call etc.
I don't want a plugin. I just need to know how to make an input and then use $_POST.
Can I do it with a custom meta box?
add_meta_box('order_payment','build_order_payment_info','orders','side');
function build_order_payment_info($post){
<input name="ID" type="hidden" value="ID of my payment">
<input name="Other info needed" type="hidden" value="">
<input name="submitPayment" type="submit" value="Process payment">
}
Then in my order meta
add_action('save_post','save_order');
function save_order(){
global$post;
if(isset($_POST['submitPayment'])&&!empty($_POST['ID'])){
//send payment api
}else echo"There was an error with the payment";
}
Would something like that work? I've also read that I can provide the custom post type to the add_action function like this: 'save_post_orders', is that correct?
Using
admin_post
action andwp_nonce_field
.When using
admin_post
it will require a hidden input within the form.When using this you want to add your action too
This will result in the form being 'submitted' to
clients::add_new_client()
I've also used
wp_nonce_feild
within my form like this