Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hi, is it possible to submit data to back end similar to data-bound without using the couch input change to <cms:input>?

I am having extreme difficulty with custom forms that have radios, checkboxes and the likes. I love couch but really do not like how forms are handled and would rather Couch not handle them. But I would like to save data as if they were being handled by data-bound forms, create snippets for the admin for improved experience.

Code: Select all
<cms:form 
masterpage='donation-results'
mode='create'
enctype='multipart/form-data'
method='post'
name='form'
id='donate_form'
action='stripe/charge.php'
>


Or can I somehow tell couch using the: <cms:db_persist_form> to take each html input and then save it to the appropriate field? If that is possible, how can I do that with data I get after submission when I receive my response from Stripe?

edit: changed subject
I think this technique that @cheesypoof came up with could work for you. viewtopic.php?p=13095#p13095

The idea is to use 2 input fields, one of them a hidden cms:input tag for doing your Couch work, and another one that is an ordinary HTML input field that works exactly how you like. By giving the two fields the same name, the input from your "live" input tag can be used in your Couch-based form processing, in this case for submitting a DBF.
Yes I thought of that. More details as I think about this further..

I need to take data from two different parts, or submit them at once at the end. Reason Being, the donation form simply asks for how much and how often. Then a button is pressed which loads the stripe checkout modal window where they enter their information, billing address, credit card and its submitted to a charge.php which handles everything.

I figured out how to map fields when I ran into this thread:
https://www.couchcms.com/forum/viewtopic.php?f=2&t=8235

But this doesn't help with the data I need to get after the form is submitted. :( The other relative data I need comes in the stripe api that I get back as a json response. Example this is how I pull fields from the stripe response, I need to save these fields to couch databound after submit when I get the values.

Code: Select all
$data_name = $stripe_new_customer->sources->data[0]->name;
$data_created = date("F j, Y, g:i a", $stripe_new_customer->created);
$data_address1 = $stripe_new_customer->sources->data[0]->address_line1;
$data_address2 = $stripe_new_customer->sources->data[0]->address_line2;
$data_city = $stripe_new_customer->sources->data[0]->address_city;
$data_state = $stripe_new_customer->sources->data[0]->address_state;
$data_zip = $stripe_new_customer->sources->data[0]->address_zip;
$data_brand = $stripe_new_customer->sources->data[0]->brand;
$data_last4 = $stripe_new_customer->sources->data[0]->last4;


So after I submit the form, is it possible to send $_POST values to a specific template that handles the databound fields using PHP on the submit file?
how can I do that with data I get after submission when I receive my response from Stripe?

This is really a separate problem. But you could use the cms:db_persist tag. It is used for saving data to the database without receiving it through a form.
So I am guessing the next step is to determine how to run a db_persist tag in my stripe charge.php that handles all the meat and potatoes of the donation, customer creation, etc.

I know how to use the db_persist tag within the form. But how can I call that in a PHP page that just interacts with the Stripe API? A page that is not a couch template. After it's done and get's it's response back, save the values as I listed above into the databound form.

I will keep looking and post if I figured it out, hopefully someone can clarify if this is even possible with couch, as I may be banging my head against a wall. Which means, I won't be able to use databound for this form or any of the others that use Stripe popup to collect the users billing information and payment information. :( Normally I would just write the code needed but I am trying to use the power of Couch to keep all data within the CMS for the user.

tim wrote:
how can I do that with data I get after submission when I receive my response from Stripe?

This is really a separate problem. But you could use the cms:db_persist tag. It is used for saving data to the database without receiving it through a form.
But how can I call that in a PHP page that just interacts with the Stripe API? A page that is not a couch template.

You can make your stripe processor a Couch template. All it takes is the boilerplate code at the beginning and end. Do whatever php processing you need, preferably within a cms:php tag, then pass your variables from php to Couch.
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
   <cms:php>
       global $CTX;

       ... Process your Stripe API...

      /* Send data from PHP to Couch */
       $CTX->set( 'data_name', $data_name );
       $CTX->set( 'data_created', $data_created );
       $CTX->set( 'data_address1', $data_address1 );
       $CTX->set( 'data_address2', $data_address2 );
       $CTX->set( 'data_city', $data_city );
       $CTX->set( 'data_state', $data_state );
       $CTX->set( 'data_zip', $data_zip );
       $CTX->set( 'data_brand', $data_brand );
   </cms:php>
   
   <cms:db_persist
      ...
      ...
      ...
        />

<?php COUCH::invoke(); ?>

Finally, use the cms:db_persist tag to save the information into the Couch database. As an aside, don't think of it as a data-bound form, but as a template updated from API data using the db_persist tag.

There are obviously some details to work out, but with a little planning and a bit of programming, what you want is certainly possible.
Here's a more complete model for a template to manage your payment processing with Couch. It's got
    - editable regions for the data
    - a php block for processing the code
    - a db_persist tag for saving the data

I think all it needs is your own php code and maybe a few tweaks to the details.

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
    <cms:template title="Stripe Payments" clonable="1">
        <cms:editable name="data_name" type="text"/>
        <cms:editable name="data_created" type="text"/>
        <cms:editable name="data_address1" type="text"/>
        <cms:editable name="data_address2" type="text"/>
        <cms:editable name="data_city" type="text"/>
        <cms:editable name="data_state" type="text"/>
        <cms:editable name="data_zip" type="text"/>
        <cms:editable name="data_brand" type="text"/>
    </cms:template>

    <cms:php>
       global $CTX;
       
       /*... Put Your Own Code Here...*/
       $data_name="hi there";
       $data_created="data_created";
       $data_address1="data_address1";
       $data_address2="data_address2";
       $data_city="data_city";
       $data_state="data_state";
       $data_zip="data_zip";
       $data_brand="data_brand";

       /* Send data from PHP to Couch */
       $CTX->set( 'data_name', $data_name );
       $CTX->set( 'data_created', $data_created );
       $CTX->set( 'data_address1', $data_address1 );
       $CTX->set( 'data_address2', $data_address2 );
       $CTX->set( 'data_city', $data_city );
       $CTX->set( 'data_state', $data_state );
       $CTX->set( 'data_zip', $data_zip );
       $CTX->set( 'data_brand', $data_brand );
   </cms:php>
   
   <cms:db_persist
            _masterpage=k_template_name
             _mode='create'
            _invalidate_cache='0'
             _autotitle='0'
            k_page_title="<cms:show data_name/>"
             data_name="<cms:show data_name/>"
             data_created="<cms:show data_created/>"
             data_address1="<cms:show data_address1/>"
             data_address2="<cms:show data_address2/>"
             data_city="<cms:show data_city/>"
             data_state="<cms:show data_state/>"
             data_zip="<cms:show data_zip/>"
             data_brand="<cms:show data_brand/>"
           />
       
<?php COUCH::invoke(); ?>   
Ok thanks tim, put it in as a template page and then clonal for the donation data to go into. This will work well. I love that I can use db_persist without forms, that opens up an entire new world for me and tieing sections of websites together.
8 posts Page 1 of 1