Send to many forms

Discussion in 'PHP' started by hurstvanrooj, Sep 30, 2007.

  1. #1
    I've just completed a database admin section for a client using PHP and MySQL and everything is working fine. It inserts / deletes / updates new items and these are searchable in a public site.

    HOWEVER :(

    They have asked for an addition;
    At the end of the forms [insert / update] they require two checkboxes that when clicked will send a form to TWO other websites [that will then display the items] and these checkboxes determine IF the info gets sent. :eek:

    [x] SEND TO COMPANY ONE
    [x] SEND TO COMPANY TWO
    [SUBMIT]

    I can't see anyway to do this and wondered if there was anyone who could give me a bit of advice.
    Thanks
    Hurst
     
    hurstvanrooj, Sep 30, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    First submit the form to your script, handle and validate it, and from there use cURL to send it to the other two sites if the checkboxes are checked.

    
    
    if (isset($_POST['site1']) OR isset($_POST['site2']))
    {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,
    		'foo=' . $_POST['foo'] . '&' .
    		'bar=' . $_POST['bar'] . '&' .
    		'var=' . $_POST['var']
    	);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	
    	if (isset($_POST['site1']))
    	{
    		curl_setopt($ch, CURLOPT_URL, 'http://site1.com/script.php');
    		curl_exec($ch);
    	}
    	if (isset($_POST['site2']))
    	{
    		curl_setopt($ch, CURLOPT_URL, 'http://site2.com/script.php');
    		curl_exec($ch);
    	}
    }
    
    PHP:
    (Code untested, but it's more of an example anyway.)

    www.php.net/curl
     
    nico_swd, Sep 30, 2007 IP
  3. hurstvanrooj

    hurstvanrooj Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks - I'm going to look at that this week and let you know how it goes.
     
    hurstvanrooj, Oct 1, 2007 IP