The Scripts Tab In this article we will describe how to attach a file of your choice to the user email. In order to achieve this custom functionality just attach this code the "Scripts" tab in the "Scripts called on form process" area: $userEmail['files'][] = $RSadapter->config['absolute_path'] . 'your/path/to/the/file/your_file.pdf'; Note: - this code will work only for RSform!Pro Rev. 17 or above - this code works only for user emails. In this article we will give step-by-step instructions on how to perform a silent post. This is particularly useful when you want the submit the values entered by the user and post them to another location, were you can perform different operations to the data. Step 1: Lets assume that you have a remote script (test.php that waits for the POST variables located at: http://yoursite.com/test.php) Step 2: Go to the “Scripts” tab and in the “Scritps called on form process” area type this code: if(isset($_POST['form']['Field1'])){ // // test HTTP POST submitter, using “libcurl” // // the target URL which contains scripts that accepts post request $url = "http://www.yoursite.com/test.php"; $useragent="YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)"; $ch = curl_init(); // set user agent curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // set the target url curl_setopt($ch, CURLOPT_URL,$url); // howmany parameter to post curl_setopt($ch, CURLOPT_POST, 1); // HERE YOU MUST SET THE VARIABLES FROM THE FORM curl_setopt($ch, CURLOPT_POSTFIELDS,"field1=".$_POST['form']['Field1']); curl_setopt($ch, CURLOPT_POSTFIELDS,"field2=".$_POST['form']['Field2']); // execute curl,fetch the result and close curl connection $result= curl_exec ($ch); curl_close ($ch); } Step 3: Click “Apply”. This example will send field1 and field2 to your remote test script. Please take into account that this should be implemented if you know what you are doing. In this article we will describe how to store the submission in a file and send it through the email.
Here's what you need to do:
1. in the Scripts called on form process, type this code:
if(isset($_POST['form']['test'])){ $fp = fopen($RSadapter->config['absolute_path'].'/components/com_rsform/uploads/test.txt', 'w'); $str = ''; foreach($_POST['form'] as $component=>$value){ if(is_array($value)) $value = implode(',',$value); $str.=$component.'='.$value."\r\n"; } fwrite($fp, $str); fclose($fp); $adminEmail['files'][] = $RSadapter->config['absolute_path'].'/components/com_rsform/uploads/test.txt'; }
2. Make sure that /components/com_rsform/uploads is 777 (writable) 3. Go to the Admin Emails, and customize it similar to this:
From: support@yourwebsite.com To: youradminthatreceivesthefile@yourwebsite.com Note: You have to fill in the rest of the email fields (leave none empty).
Here's how it will work:
1. The user submits 2. The system writes test.txt in /components/com_rsform/uploads/test.txt 3. The system attaches this file to the mail sent to the admin.
In this article we will describe how to ensure that the registry number is correct. For instance, if you enter a registration number, it must only allow a number which is on a predefined list. It will not allow a number which is not known. These codes will not be visible to the public. In order to achieve this, just edit your form, go to "Scripts" tab and place this code: if(isset($_POST['form']['RegistrationCode']))
{ $validCodes = array('AAAA','BBBB','CCCC','DDDD'); $foundValid = false; foreach($validCodes as $validCode) if( strtolower($validCode) == strtolower($_POST['form']['RegistrationCode'])) $foundValid = true;
if(!$foundValid) { $invalid[]=RSresolveComponentName('RegistrationCode',$formId); echo RSshowForm($formId, $_POST['form'], $invalid); } }
Note: Instead of "RegistrationCode" you have to put in the name of the textbox form component that will hold the registration code filled in by the user. |