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 https://stackoverflow.com/a/6753281/1445460
Not sure how I ran into this question one year later, but since it is unanswered…
Instead of self-submitting the form and then redirecting to Paypal, you can instead have the paypal url as your form’s action, but use Ajax to save the form data before the form is submitted to Paypal. You can also use the Ajax response to prepare the form before submission, e.g. filling some hidden fields
Here’s an example:
myform.php:
saveform.php: Processes the Ajax request and returns a response that can be used to manipulate the form before submission
myform.js: Submits form data to saveform.php before submitting to paypal
Instead of the jquery.ajax call you can also use the shorter:
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: