Discussion Forums

Web Form Code Help

 
Avatar
Enthusiast
11 posts

Hey there!

does anyone have any code examples for creating a contact with a formatted note in Solve after someone fills out a web form? I am using the example code for the contact form provided on this website, but I am not sure how to get message text (i.e. a multi-line text area) into Solve within a note. I am an enthusiastic hack at this stuff but not an expert by any means. Any help on this would rule.

Thanks.

Avatar
Administrator
3943 posts

Thanks for the question, here is an example…

Add a input to your web-form to capture the note data:

<textarea name="note" cols="4" rows="4"></textarea

Post that data into a new note by making two changes to your script:

1) Remove the note value from the default array

// Remember the note activity text
$noteText $dataArray['note'];
// Remove it from the data, we will add it later
unset($dataArray['note']); 

2) Add a new section to post the note to Solve in a separate transaction

// Adding note activity 
// Connection to the host
$fp fsockopen("ssl://" HOST443$errno$errstrTIMEOUT);

if (!
$fp{
    
die('Cannot connect to Solve360 host');
else {
    
    
// Preparing data for the note
    
$noteText str_replace("\n""<br/>"$noteText);
    
    
    
// Forming new data
    
$dataArray = array(
        
'parent' => $newContactId,
        
'data'   => array (
            
'details' => $noteText
        
)
    );
    
$data http_build_query($dataArray);
    
    
// Prepare request body
    
$request "POST /contacts/note HTTP/1.1\r\n";
    
$request .= "Host: ".HOST."\r\n";
    
// Authorization header
    
$request .= "Authorization: Basic ".base64_encode(USER.":".TOKEN)."\r\n";
    
// We inform the server that we're sending data in form encoded format
    
$request .= "Content-Type: application/x-www-form-urlencoded\r\n";
    
// We inform the server theat we are waiting for xml formatted data in response
    
$request .= "Accept: application/xml\r\n";
    
$request .= "Content-Length: ".strlen($data)."\r\n";
    
$request .= "Connection: close\r\n\r\n";
    
$request .= $data;

    
// Send request to the host
    
fwrite($fp$request);
    
stream_set_timeout($fpTIMEOUT);
    
$info stream_get_meta_data($fp);

    
// Read the response
    
$response '';
    while (!
feof($fp) && !$info['timed_out']{
        $newLine 
stream_get_line($fp1024"\n");
        
$response .= $newLine;
        if (
trim($newLine) === '0'{
          
break;
        
}
        $info 
stream_get_meta_data($fp);
    
}
    fclose
($fp);

    
// Get xml from response
    
$results    explode('<?xml'$response);
    if (!empty(
$results[1])) {
        $xml 
simplexml_load_string("<?xml ".$results['1']);

        
// Mail the user with the result information
        
mail(USER'Note was added to "' $newContactName '" contact in Solve360'
             
'Note with id ' . (string) $xml->id ' was added to the contact '  
                 
' with id ' $newContactId);
    
else {
        
// Something went wrong and we haven't got xml in the response
        
die('System error');
    
}
    
    
if (isset($xml->errors)) {
       mail
(USER'Error while adding note to a contact Solve360''Error: ' $xml->errors->asXml());
       die (
$xml->errors->asXml());
    
}
}
// End of adding note activity 

To make this easier to follow ‘in context” we’ll update our API docs to include this example.

Avatar
Enthusiast
11 posts

Thanks! This is really excellent, and I can see that this is going to work well but there seems to be a slight problem somewhere.

I added everything as specified, and it does create a note activity within Solve after submitting the form, however, the note is blank (i.e. the text inputted into the textarea does not seem to be carrying over unfortunately).

Any thoughts on this? I can send you the page or attach files if need be.

Avatar
Administrator
3943 posts

As we’ve extended the basic web-form example to do more things the sample script has become a bit unwieldy.  Internally we’ve developed and use a small Solve “services library” to help us get API work done quickly.  We’re re-factoring the web-form example to use this small library now.  This will eliminate redundant calls, give the script some decent structure ... making it much simpler for you to follow and support too. If you can hang on for a couple of hours we should be able to share it with you today, which would make following along with your Note example easier too.

Avatar
Administrator
3943 posts

The updated example is now online if you’d like to be the first to test it out http://is.gd/518L1

Lyncean
51 posts

I would be interested in knowing more about Joomla integration:
Are there plans for Web Form API’s to be available as Joomla modules?

Avatar
Enthusiast
11 posts

Hey there -
I finally had a chance to really test this, and (while the new sample code is way more intuitive to set up, thank you) something still seems amiss. Perhaps it would be easier for you to see it in action first-hand, so the link to the form is below. The only changes I made to the script in the new zip file you guys posted are the required log-in and token section, and I also enabled sharing, category tags, and the creation of a note. I don’t see any red flags so I’m not sure why it’s not working.

Thanks for your help!
http://www.apexgreenroofs.com/Solve360Example/Solve360ContactForm.html

Avatar
Administrator
3943 posts
Floydie - Mar 09, 2010 04:11pm

I would be interested in knowing more about Joomla integration:
Are there plans for Web Form API’s to be available as Joomla modules?

We’re reviewing ideas related to providing generic webforms but nothing specific to Joomla

Avatar
Administrator
3943 posts
Apex Green Roofs - Mar 10, 2010 12:06pm

Hey there -
I finally had a chance to really test this, and (while the new sample code is way more intuitive to set up, thank you) something still seems amiss. Perhaps it would be easier for you to see it in action first-hand, so the link to the form is below. The only changes I made to the script in the new zip file you guys posted are the required log-in and token section, and I also enabled sharing, category tags, and the creation of a note. I don’t see any red flags so I’m not sure why it’s not working.

Thanks for your help!
http://www.apexgreenroofs.com/Solve360Example/Solve360ContactForm.html

Since I can’t see your script directly I copied the default one to our own system here and set your parameters (email, token, owner, tag and note) then submitted a form.  It seemed to work fine (please find the contact “Norada Support” in your account and remove it.  Perhaps email us your script when you can and we’ll see what’s different.

Avatar
Enthusiast
11 posts

This worked - it’s great. Thanks very much!

Lyncean
51 posts

I recently attended a Joomla users group meeting in a Toronto pub. There are about 15 members (designers etc), and also developers – 2 of the organisers in this group actually release the core Joomla code. I asked them about integrating Solve360, but they only knew of SugarCRM integration.

I know they are keen to extend the use of Joomla (especially as Drupal and Wordpress are also expanding) and I would like to see if Solve360 integration would be of interest, but am not sure of API language, and developer protocol. Do you have a standard pdf about Solve360 API development, which I could forward onto them. May come to nothing… but could be worth a try.