PDA

View Full Version : Can formail do this?



CHMOD000
20-Jun-2007, 11:25 PM
I have radio buttons in my form that let a person say they want to be added to my email list or not, and usually I will input their email address manually into the list.

I have a form, seperate from my email form, that allows people to sign up for my email list.

This is what that form looks like:


<form method="post" action="http://something.com/subscribe.aspx?Task=Join">
<p class="heavy">Your Name:<br />
<span class="email-input">
<input type="text" name="Name" size="24" maxlength="100"></input>
</span>
</p>
<p class="heavy">Your E-mail Address:<br />
<!--webbot bot="Validation"
S-Display-Name="Email Address"
B-Value-Required="TRUE"
I-Minimum-Length="7"
I-Maximum-Length="255" -->
<span class="email-input">
<input type="text" name="Email" size="24" maxlength="255"></input>
</span>
</p>
<p class="heavy"><input type="submit" value="Subscribe" name="B1"></input></p>
<div>
<input type="hidden" value="526" name="NewsletterListID"></input>
<input type="hidden" value="HTML" name="DeliveryFormat"></input>
<input type="hidden" value="RandomNumber" name="Password"></input>
<input type="hidden" name="JoinType" value="Menu"></input>
<input type="hidden" value="{CDFEB2A7-0B0C-4541-A50B-CC975DDB114A}" name="SID"></input>
</div>
</form>


So, I'm wondering if the person "checks" the yes radio button in my email form, if there is a way to have the person automatically added to the email list so I don't have to do it manually.

Thanks for any help.

russellr
21-Jun-2007, 02:51 AM
Hi,

By "email list" do you mean a list of email addresses (with, possibly, names) from which you do some mass mailing, such as sending a newsletter?

FormMail can write directly to a CSV file, which can contain such information.

Whether this suits you depends on what the software that wants to read this list requires.

If you need something other than a CSV file format, then FormMail can help you do this. It will require some additional PHP code to write to the file in the correct format.

In short, you need to completely specify what you need to happen before I can provide an exact answer.

CHMOD000
21-Jun-2007, 05:25 AM
The form code that I posted above is what my host supplied to me. Users who elect to subscribe to my email newsletter simply type their name and email address into the form, and hit the submit button. You can see the form live at http://www.tv-sewingcenter.com/email.php

I don't really know what happens once the submit button is pressed, but the username and email address are updated to a database somewhere, and then they are directed to a page that says that they can check their email to confirm their subscription. If you want to test the form to see what happens, go ahead and just put in a fake email address.

If you view my actual tectite email form:

http://www.tv-sewingcenter.com/contact.php

you will notice in the form the radio button to select that you want to subscribe to my email newsletter. What I'd like to happen is, if a user has checked YES, that when they submit their email to me via tectite formmail processing script, I'd ALSO like their name and email address to be sent through the newsletter sign up form to be added to the database.

This is as much info as I can give you without contacting my host.

russellr
21-Jun-2007, 05:43 AM
Hi,



What I'd like to happen is, if a user has checked YES, that when they submit their email to me via tectite formmail processing script, I'd ALSO like their name and email address to be sent through the newsletter sign up form to be added to the database.


OK, that's not going to happen automatically.

I'm sure it can be done, but it requires some research into what the current newsletter subscription script does and then development of some additional code to operate with FormMail.

If you'd like to hire me to do this, please contact me by email: http://www.tectite.com/contacts.php

CHMOD000
21-Jun-2007, 12:42 PM
I will try it myself and let you know Russel. I have an idea of how it could work, and I do have experience writing php, but I was just hoping for a quick and easy solution from somebody that knows the code.

russellr
21-Jun-2007, 07:53 PM
Hi,

The best way to do this is to write the PHP code in a separate file and use FormMail's Hook System to include your code at the right point.

If you understand PHP you will follow it quite easily - look for HOOK_DIR.

CHMOD000
22-Jun-2007, 01:06 PM
Thanks for the tip Russel. I will let you know what happens.

CHMOD000
23-Jun-2007, 03:39 AM
I used this as my fmhookprefinish.inc:



<?php
if ($aCleanedValues['opt-in'] == 'Y'){
$name = $_POST['realname'];
$email = $_POST['email'];
$url = "http://newsletters.sewchannel.com/subscribe.aspx?Task=Join";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); //needed for some reason
curl_setopt($ch, CURLOPT_TIMEOUT, 30); // times out after 31s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, array('Name'=>"$name",'Email'=>"$email",'DeliveryFormat'=>'HTML','Password'=>'RandomNumber','SID'=>'{CDFEB2A7-0B0C-4541-A50B-CC975DDB114A}')); // add POST fields
curl_exec($ch); // run the whole process
curl_close($ch);
}
?>

The only thing is, Id rather use the cleaned values, but when I tried it gave me an error. Something about the name not being a acceptable name. Other than that, it is doing exactly what I want it to do. Hey Russel, do I need to decode this or something? Thanks again for the tip on HOOK_DIR.

russellr
23-Jun-2007, 06:34 AM
Hi,

I don't know without the exact error message. $aCleanedValues is correct.

This is really now "support" instead of "features questions", so you need to subscribe for further assistance.

CHMOD000
24-Jun-2007, 05:59 AM
I just decided to filter my own input. It may not be as fancy as your filter, but it's probably good enough:



$prename = $_POST['realname'];
$nameRegex = "/^[A-Z ]{2,125}$/i";
$preemail = $_POST['email'];
$emailRegex = "/^[A-Z0-9._-]{1,100}@[A-Z0-9._-]{1,100}\.[A-Z.]{2,6}$/i";
if(preg_match($nameRegex,$prename) && preg_match($emailRegex,$preemail)) {
$name = $prename;
$email = $preemail;
}else{
die();
}