ajax form submit to php file and to url?
<p>I have a subscribe form in wordpress that (currently) only has the ability to add submitted email to a custom post type (<code>subscribers</code>) and show it in backend.I am wondering how to also have this functionality, and send this email to a custom url (concretely to APSIS).</p>

<p>So I have a form</p>

<pre><code>&lt;form id="subscribe" class="subscribe_form" name="subscribe_form" action="#" method="post"&gt;
    &lt;input name="subscriber_email" class="subscriber_email" placeholder="Your mail here"&gt;
    &lt;input class="submit" type="submit" value="Submit"&gt;
&lt;/form&gt;
</code></pre>

<p>My save custom post type function that gets executed via AJAX</p>

<pre><code>&lt;?php 

add_action('wp_ajax_save_subscriber', 'save_subscriber');
add_action('wp_ajax_nopriv_save_subscriber', 'save_subscriber');

if (!function_exists('save_subscriber')) {
    function save_subscriber() {

        if (isset($_POST['subscriber_email']) &amp;&amp; is_email($_POST['subscriber_email'])) {
            global $wpdb;
            $post_data = array(
                'post_type' =&gt; 'subscribers',
                'post_status' =&gt; 'publish'
            );
            $published_id = wp_insert_post( $post_data );
            add_post_meta($published_id, 'subscriber_email', $_POST['subscriber_email']);
            $out = 'OK';
        } else{
            $out = 'ERROR';
        }

        die($out);
    }
}
</code></pre>

<p>And my AJAX</p>

<pre><code>$('#subscribe').submit(function() {
    'use strict';
    var str = $(this).serialize() + '&amp;action=save_subscriber';
    var $form = $(this);
    var $wrapper = $(this).parent();
    $.ajax({
        type: 'POST',
        url: custom.ajaxurl,
        data: str,
        success: function(msg){
            if( msg === 'OK' ) {
                $form.animate({ height: '0px' }, 800, function() {
                    $form.hide();
                });
                $wrapper.find('.success_message').delay(400).html(custom.success).slideDown(600);
            }else {
                $wrapper.find('.subscriber_email').addClass('field_error').attr('placeholder', custom.error_mail).val('').focus();
            }
        }
    });
    return false;
});
</code></pre>

<p>Now I have some more wrappers, and noonce field etc. but that's not important here.</p>

<p>This works fine when you want to just add a post to the CPT, but I need to submit this to </p>

<pre><code>http://www.anpdm.com/public/process-subscription-form.aspx?formId=xxxxxxxxxxx
</code></pre>

<p>I got the id and everything from the client, now I need to implement this.</p>

<p>I've seen something about curl, but I've never done anything with it, so I don't really know where to start. Since my action is pointing to my <code>save_subscriber()</code> function I recon that in that function I'd also have to add a way to send this form to the required url. But how?</p>

<p>Any info will help, thanks.</p>

<h2>ANSWER</h2>

<p>So following the answer provided by silver, I managed to get it working.</p>

<pre><code>#Run CURL
$url = 'http://www.anpdm.com/public/process-subscription-form.aspx?formId=xxxxxxxxxx';

$request = curl_init();
curl_setopt_array( $request, array (
    CURLOPT_RETURNTRANSFER =&gt; TRUE,
    CURLOPT_URL =&gt; $url,
    CURLOPT_POST =&gt; 1,
    CURLOPT_USERAGENT =&gt; 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13',
    CURLOPT_POSTFIELDS =&gt; $custom_query_string,
));
$response = curl_exec($request);
$response_data = curl_getinfo($request);
curl_close($request);

#END CURL
if ($response_data['http_code'] == 200) {
    $out = 'OK';
}
</code></pre>

<p>The <code>formId</code> is the form number specific for this user, and the <code>$custom_query_string</code> conformed to the form provided by APSIS and contained something like this:</p>

<pre><code>pf_Email=$_POST['email']&amp;
Submit=Prenumerera&amp;
pf_DeliveryFormat=HTML&amp;
pf_MailinglistName1=xxxxx&amp;
pf_FormType=OptInForm&amp;
pf_OptInMethod=SingleOptInMethod&amp;
pf_CounterDemogrFields=0&amp;
pf_CounterMailinglists=1&amp;
pf_AccountId=xxxx&amp;
pf_ListById=1&amp;
pf_Version=2
</code></pre>

<p>After that all worked, I get my subscribers in the wordpress backend, and they appear in the APSIS console where the users are :)</p>

<p>I guess I needed user_agent and correct query string.</p>