0

I'm building a stripe plugin and I'm stuck on this minor major issue.

Problem: the form calls my process.php page to grab the form input variables, handle the Stripe token, and finally call out to Stripe to build a new customer based on all params being completed successfully. Once this sheet is called the wp functions in this sheet are all undefined.

My theory is that when the form requests the php sheet the server clears its cache and loads the requested sheet fresh, which dumps all the wp globals I need.

Question: how do I call from my form to my custom php sheet, and still have access to the wp global functions? small wrinkle, the form is built in another plugin

I hope this makes sense, let me know if I need to clarify this more.

folder structure:

plugins
 -->other plugin
    -includes
      --template-functions.php(form is built here)
 -->my plugin
    -includes
    -languages
    -lib
    -custom-form-processing.php

code: form build in template-functions.php

<form id="<?php echo $form_id; ?>" action="<?php echo plugins_url() . '/lmf-stripe/includes/process-customer.php' ?>" method="post">
--inner form bits here
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="<?php echo $newKey; ?>"   data-amount="<?php echo $amount*100; ?>" data-description="<?php the_title_attribute(); ?>"></script>
</form><!--end #<?php echo esc_attr( $form_id ); ?>-->

process-customer.php

<?php
function setCustomer()
{
if (isset($_POST['action']) && $_POST['action'] == 'stripe' && wp_verify_nonce($_POST['stripe_nonce'], 'stripe-nonce')) {

    global $stripe_options;

    <!-- inner bits removed for brevity -->

    // redirect back to our previous page with the added query variable
    wp_redirect('http://www.google.com');
    exit;
  }
}

 add_action('init', 'setCustomer');
?>
  • Forms in WordPress should submit to a WordPress-generated front-facing or admin page so the WordPress environment is present. Do you have control over where the form submits to? – Milo Jan 26 '15 at 21:49
  • yes I have control over where the form submits to. I'm following your logic, just not sure how to implement or begin to implement. – atlMapper Jan 26 '15 at 21:59
1

WordPress provides wp-admin/admin-post.php endpoint to work with form submissions.

You should likely point your form to it, add an identifying action, and use hooks in the file to process submission.

  • ok cool, I like the logic, if I'm understand this correctly point to the admin-post.php end point then use hooks to continue the functionality. cool. I'll do a bit of reading on admin-post.php. Thanks – atlMapper Jan 26 '15 at 22:23
0

You can achieve what you want using ajax, which, in WordPress, is handled by admin-ajax.php. It's all in here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.