Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to submit form data to the database then send the client over to paypal which will use IPN to send a response back.

Right now I have the form submitting to the database, I have the IPN working, my problem is the redirecting part. I want it all to be done in with the click of one button...

My form just submits back to the current page where it validates data and adds to the database. I can't seem to use header because data is already sent to the header.

What are my options/solutions. Simplest solution would be best but I'm open to anything at this point.

For such a simple task you would think there would be a simple solution...

Here's my code that prints out the form:

function display_form() { ?>
        <div class="culis-module">
            <form action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>" method="post">      
                <div class="clearfix culis-module-body">
                    <?php 
                    if ( $_POST['culis_add_listing'] == 'Y' && $this->no_errors()) { 
                        $this->addto_db();
                        ?><div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">x</button> <?php _e('Thank You, your company will be listed as soon as payment is processed.')?></div><?php 
                    }

                    if ( $_POST['culis_add_listing'] == 'Y' && !$this->no_errors()) { 
                        $this->prepare_fields('saved'); 
                    } 
                    else {
                        $this->prepare_fields();
                    }?>
                </div>
                <div class="modal-footer">  
                    <button class="btn btn-primary" type="submit" name="culis_add_listing" value="Y">Submit</button>
                    <button class="btn" type="submit" name="form_reset" value="Y">Clear</button>
                </div>
            </form>
        </div>
    <?php 
    }

Update: Here is an example of what I'm trying to do http://stackoverflow.com/a/6753281/1445460

share|improve this question

1 Answer

Indeed there is a simple solution. I assume you're doing the form processing and attempting to redirect in your template? You need to hook an earlier action, before headers are sent. example:

function wpa66284_process_my_form(){
    if( isset( $_POST['myform'] ) ){
        // process form and redirect
    }
}
add_action( 'init', 'wpa66284_process_my_form' );
share|improve this answer
Well its actually being called from a plugin, if that matters. I updated to show the section that prints the form. I would have to put my redirect after the $this->addto_db();. – Kirill Fuchs Sep 26 '12 at 1:06
the code may be in a plugin, but your display_form function is being called from the template or an action that occurs in the template, processing needs to happen before output begins. – Milo Sep 26 '12 at 1:52
How do I get it to happen before output begins? I tried add_action( 'init', array($this, 'addto_db')); but that didn't do anything. It didn't seem to call my function :(. Am I missing something? – Kirill Fuchs Sep 26 '12 at 1:55
So this is an example of exactly what I'm trying to do. stackoverflow.com/a/6753281/1445460 My problem is I don't know how to redirect to paypal after I have done all the database stuff. – Kirill Fuchs Sep 26 '12 at 1:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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