Hi.

Is there any site where I can see the form_mail module in action?

Also I'd like to have a sample form to use as a base.

I'm planning some arbitrary forms including a tell a freind so I'd like to be able to include the reffering page as a hidden field in the form.

Comments

Tarlbot’s picture

Title: Looking for samples. » form_mail sample.
Anonymous’s picture

boris mann’s picture

Assigned: Unassigned » boris mann

I think this might be more useful as a code example. Easiest way to do this is create a static page with content set to PHP and this included in it. Of course, a block or any other place you can input PHP in Drupal would work as well.


$form .= form_textfield("Subject", "subject", "", 60, 70);
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "Please fill this out if you would like a response by email");
$form .= form_textarea("Message", "body", "", 60, 15);

$form .= form_submit("Send email");

echo form($form, "post", "form_mail");

Look at the form functions in common.inc for more details.

Anonymous’s picture

Category: feature » bug

I added this code to a static page, saved as php, and got an error message. This is with a fresh drupal 4.4 installation with form_mail 4.4 installed. Can anybody help?

Parse error: parse error in /home/palchemy/public_html/modules/page.module(129) : eval()'d code on line 1

Anonymous’s picture

try it without "" and ""

Like this

$form .= form_textfield("Subject", "subject", "", 60, 70);
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "Please fill this out if you would like a response by email");
$form .= form_textarea("Message", "body", "", 60, 15);

$form .= form_submit("Send email");

echo form($form, "post", "form_mail");

wimvos’s picture

Same error, although i have deleted the quotes, does not work.

cherylchase’s picture

This works for me (drupal 4.4.1). Note that the static page content should just contain only:

[quote]
$form .= form_textfield("Subject", "subject", "", 60, 70);
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "Please fill this out if you would like a response by email");
$form .= form_textarea("Message", "body", "", 60, 15);

$form .= form_submit("Send email");

echo form($form, "post", "form_mail");
[/quote]

kc’s picture

it works but where does it send the email and how can one specify another page for the user to be forwarded to after successfull sending?

trailerparkopera’s picture

Here's what I've worked out for my own needs. This form template hides the "EmailTo" field (that overrides the form_mail default) and "EmailSubject" field in the form, but posts a default value for those fields. I use it to subscribe people to an email list I have on a separate server, running a different system.

[quote]
$form .= form_hidden("to", "(INSERT TO: ADDRESS HERE");
$form .= form_hidden("subject", "(INSERT SUBJECT: ADDRESS HERE")");
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "(CUSTOMIZE MESSAGE AT BOTTOM OF FORM HERE)");
$form .= form_hidden("Message", "body", "", 60, 15);
$form .= form_submit("Sign me up!");

echo form($form, "post", "?q=form_mail");
[/quote]

Anonymous’s picture

Category: bug » support

i included the module form_mail and inserted the code example from above
the form elements are drawn well, but when sending the form it just tries to jump to the location form_mail not sending the form.

How do I connect my form with the form_mail module?

thanks florian

lgm@drupal.org’s picture

I used trailerparkopera's example "submitted by trailerparkopera on June 29, 2004".
the only change I needed was from :

echo form($form, "post", "form_mail"); 

to this :

echo form($form, "post", "?q=form_mail");
jcosters’s picture

I think you should use

echo form($form, "post", url("form_mail"));

url() constructs a clean URL or a normal (?q=...) URL, depending on your setting in the administration section. That way your code is independant of either type of URL.

seanr’s picture

Title: form_mail sample. » More than one "To" field?

I know you can put multiple address in the two field separated by commas, but I'm doing an invite form and would rather use separate fields for each address (to make it more obvious to the user). How would I go about this? Here's the code I'm using right now:

$form .= form_textfield("To", "to", "", 60, 128);
$form .= form_hidden("subject", "Join Virginia Partisans and fight for your rights!");
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "(CUSTOMIZE MESSAGE AT BOTTOM OF FORM HERE)");
$form .= form_textarea("Message", "body", "", 60, 15);
$form .= form_submit("Sign me up!"); 

echo form($form, "post", "form_mail");

Can you do something like this:

$form .= form_textfield("To", "to[0]", "", 60, 128);
$form .= form_textfield("", "to[1]", "", 60, 128);
$form .= form_textfield("", "to[2]", "", 60, 128);
$form .= form_textfield("", "to[3]", "", 60, 128);
$form .= form_textfield("", "to[4]", "", 60, 128);
etc.
seanr’s picture

Title: More than one "To" field? » form_mail sample.

(fixed title - had accidentally changed it)

Steven’s picture

$form .= form_hidden("to", "(INSERT TO: ADDRESS HERE");
$form .= form_hidden("subject", "(INSERT SUBJECT: ADDRESS HERE")");

This should be avoided. It allows anyone to send email using your site and a custom form. It is best to put the to/subject on the server side, and fill it in after the form is submitted. You should also look into throttling, to prevent mass emailing/spamming.

Dries' upcoming Contact.module has such a generic mechanism.

wheelweb’s picture

Hi,

I want to create a form where I can send additional information via email such as Krankenversicherung, Gender etc. This information should be sent in the subject of the email.

How can I do this?

I use this code now:

$form .= form_textfield("Subject", "subject", "Ich möchte einen Termin vereinbaren", 60, 70);
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "Bitte geben Sie hier Ihre email-Adresse ein, damit wir Sie kontaktieren können.");
$form .= form_textfield("Geburtsdatum", "body", "", 60, 128, "optional");
$form .= form_textfield("Krankenversicherung", "Krankenversicherung:", "", 60, 128, "optional");
$form .= form_textarea("Message", "body", "", 60, 15);
$form .= form_submit("Send email");
echo form($form, "post", "?q=form_mail");

Thanks a lot!

lvadillo’s picture

I'm working with the module and knowing "0" about php is not an easy task. The module looks simple and works fine if at the end I use:

echo form($form, "post", "form_mail"); as shown in the samples above.

I need some help on the following:

I have already set up a "Thank You" page for the form to go when pressing the "send" buttom, so I need in the mentioned line to substitute "form_mail" with "node/xxx", but that doesn't work as "form_mail" is the one that actually sends the email.
1) Is there a way to put some php coding in "node/xxx" so to be able to send the email and avoid the "form_mail" page display?

(I've tried aliasing the "node/xxx" as "form_mail" but that doesn't work)

As secondary wishes:

2) If in the form I ask for the user to put his/her email in one of the variables, is there a way to pass it so that the email is sent to me and to him/her? (a confirmation email)

3) Is there a way to add the YYY variable in the email (form) that equals the sender IP? (in case there is abuse I could know from where it comes).

Thank you.

boris mann’s picture

Use one of forms.module, survey.module, webforms.module, contact.module, feedback.module

gauz’s picture

Status: Closed (fixed) » Active

Hi all, I need sample of this module for multiple choice, checkbox, radio and all type of form if posible.

boris mann’s picture

Status: Active » Closed (fixed)

Use the forms.module instead, and inspect the code to see how to call the PHP.

If you would like to create forms directly, you can use either the survey module or the webforms module.

Leeteq’s picture

Step by step procedure on making a mail form after the form_mail module has been installed and enabled: (version 4.6.x)

1. Make a new Page, book page, or whatever content type you want.
2. Set the desired title and categories.
3. Select to use PHP code, not HTML. (perhaps only Administrators can do this, depending on the actual permissions on that portal)
3. Click in the BODY text field
4. If you are using a WYSIWYG tool that lets you format text in the body text field easily, click on a button called "Toggle HTML source" or something similar to that.
5. Paste the following: (IMPORTANT: NO trailing spaces..!)

$form .= form_textfield("Subject", "subject", "", 60, 70);
$form .= form_textfield("Name", "from_name", "", 60, 128);
$form .= form_textfield("Email", "from_email", "", 60, 128, "Please fill this out if you would like a response by email");
$form .= form_textarea("Message", "body", "", 60, 15);
$form .= form_submit("Send email");
echo form($form, "post", "form_mail");

6. Submit your page, do not toggle back to HTML in the body text.

Now your form should be displayed.

Leeteq’s picture

By the way, you have to configure the module after enabling it, of course:
- enter the receiving mail address in Administer/form mail, and
- give access to the form_mail module in Administer/Access Control.

snackmaster’s picture

Any way to validate fields, especially email so as to help prevent people from inputting an invalid address by mistake, therefore I never recieve the form and the sender thinks I'm ignoring them?

zepernick’s picture

I went through the include file and pulled out all of the form functions, in case anyone needs them.


/**
 * Format a radio button.
 *
 * @param $title
 *   The label for the radio button.
 * @param $name
 *   The internal name used to refer to the button.
 * @param $value
 *   The value that the form element takes on when selected.
 * @param $checked
 *   Whether the button will be initially selected when the page is rendered.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $attributes
 *   An associative array of HTML attributes to add to the button.
 * @param $required
 *   Whether the user must select this radio button before submitting the form.
 * @return
 *   A themed HTML string representing the radio button.
 */
function form_radio($title, $name, $value = 1, $checked = FALSE, $description = NULL, $attributes = NULL, $required = FALSE)




/**
 * Format a set of radio buttons.
 *
 * @param $title
 *   The label for the radio buttons as a group.
 * @param $name
 *   The internal name used to refer to the buttons.
 * @param $value
 *   The currently selected radio button's key.
 * @param $options
 *   An associative array of buttons to display. The keys in this array are
 *   button values, while the values are the labels to display for each button.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $required
 *   Whether the user must select a radio button before submitting the form.
 * @param $attributes
 *   An associative array of HTML attributes to add to each button.
 * @return
 *   A themed HTML string representing the radio button set.
 */
function form_radios($title, $name, $value, $options, $description = NULL, $required = FALSE, $attributes = NULL) 




/**
 * Format a checkbox.
 *
 * @param $title
 *   The label for the checkbox.
 * @param $name
 *   The internal name used to refer to the button.
 * @param $value
 *   The value that the form element takes on when selected.
 * @param $checked
 *   Whether the button will be initially selected when the page is rendered.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $attributes
 *   An associative array of HTML attributes to add to the button.
 * @param $required
 *   Whether the user must check this box before submitting the form.
 * @return
 *   A themed HTML string representing the checkbox.
 */
function form_checkbox($title, $name, $value = 1, $checked = FALSE, $description = NULL, $attributes = NULL, $required = FALSE) 


/**
 * Format a set of checkboxes.
 *
 * @param $title
 *   The label for the checkboxes as a group.
 * @param $name
 *   The internal name used to refer to the buttons.
 * @param $values
 *   A linear array of keys of the initially checked boxes.
 * @param $options
 *   An associative array of buttons to display. The keys in this array are
 *   button values, while the values are the labels to display for each button.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $attributes
 *   An associative array of HTML attributes to add to each button.
 * @param $required
 *   Whether the user must check a box before submitting the form.
 * @return
 *   A themed HTML string representing the checkbox set.
 */
function form_checkboxes($title, $name, $values, $options, $description = NULL, $attributes = NULL, $required = FALSE) 


/**
 * Format a single-line text field that does not display its contents visibly.
 *
 * @param $title
 *   The label for the text field.
 * @param $name
 *   The internal name used to refer to the field.
 * @param $value
 *   The initial value for the field at page load time.
 * @param $size
 *   A measure of the visible size of the field (passed directly to HTML).
 * @param $maxlength
 *   The maximum number of characters that may be entered in the field.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $attributes
 *   An associative array of HTML attributes to add to the form item.
 * @param $required
 *   Whether the user must enter some text in the field.
 * @return
 *   A themed HTML string representing the field.
 */
function form_password($title, $name, $value, $size, $maxlength, $description = NULL, $attributes = NULL, $required = FALSE) 


/**
 * Format a multiple-line text field.
 *
 * @param $title
 *   The label for the text field.
 * @param $name
 *   The internal name used to refer to the field.
 * @param $value
 *   The initial value for the field at page load time.
 * @param $cols
 *   The width of the field, in columns of text.
 * @param $rows
 *   The height of the field, in rows of text.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $attributes
 *   An associative array of HTML attributes to add to the form item.
 * @param $required
 *   Whether the user must enter some text in the field.
 * @return
 *   A themed HTML string representing the field.
 */
function form_textarea($title, $name, $value, $cols, $rows, $description = NULL, $attributes = NULL, $required = FALSE) 



/**
 * Format a dropdown menu or scrolling selection box.
 *
 * @param $title
 *   The label for the form element.
 * @param $name
 *   The internal name used to refer to the form element.
 * @param $value
 *   The key of the currently selected item, or a linear array of keys of all the
 *   currently selected items if multiple selections are allowed.
 * @param $options
 *   An associative array of buttons to display. The keys in this array are
 *   button values, while the values are the labels to display for each button.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $extra
 *   Additional HTML to inject into the select element tag.
 * @param $multiple
 *   Whether the user may select more than one item.
 * @param $required
 *   Whether the user must select a value before submitting the form.
 * @return
 *   A themed HTML string representing the form element.
 *
 * It is possible to group options together; to do this, change the format of
 * $options to an associative array in which the keys are group labels, and the
 * values are associative arrays in the normal $options format.
 */
function form_select($title, $name, $value, $options, $description = NULL, $extra = 0, $multiple = FALSE, $required = FALSE) 



/**
 * Format a file upload field.
 *
 * @param $title
 *   The label for the file upload field.
 * @param $name
 *   The internal name used to refer to the field.
 * @param $size
 *   A measure of the visible size of the field (passed directly to HTML).
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $required
 *   Whether the user must upload a file to the field.
 * @return
 *   A themed HTML string representing the field.
 *
 * For assistance with handling the uploaded file correctly, see the API
 * provided by file.inc.
 */
function form_file($title, $name, $size, $description = NULL, $required = FALSE) 



/**
 * Store data in a hidden form field.
 *
 * @param $name
 *   The internal name used to refer to the field.
 * @param $value
 *   The stored data.
 * @return
 *   A themed HTML string representing the hidden field.
 *
 * This function can be useful in retaining information between page requests,
 * but be sure to validate the data on the receiving page as it is possible for
 * an attacker to change the value before it is submitted.
 */
function form_hidden($name, $value) 



/**
 * Format a form submit button.
 *
 * @param $value
 *   Both the label for the button, and the value passed to the target page
 *   when this button is clicked.
 * @param $name
 *   The internal name used to refer to the button.
 * @param $attributes
 *   An associative array of HTML attributes to add to the form item.
 * @return
 *   A themed HTML string representing the button.
 */
function form_submit($value, $name = 'op', $attributes = NULL) 




/**
 * Format a weight selection menu.
 *
 * @param $title
 *   The label for the form element.
 * @param $name
 *   The internal name used to refer to the form element.
 * @param $value
 *   The selected weight value at page load time.
 * @param $delta
 *   The largest in absolute value the weight can be. For example, if set to 10,
 *   weights could range from -10 to 10 inclusive.
 * @param $description
 *   Explanatory text to display after the form item.
 * @param $extra
 *   Additional HTML to inject into the select element tag.
 * @return
 *   A themed HTML string representing the form element.
 */
function form_weight($title = NULL, $name = 'weight', $value = 0, $delta = 10, $description = NULL, $extra = 0) 





ryanrain’s picture

Version: » 4.6.x-1.x-dev
Component: Documentation » Code

i followed the instructions in comment #21 to a tee, but when i click submit i get a Not Found error. i can't seem to get clean URL's to work, so that may be the problem, it can't find me.com/form_mail.

can anyone suggest how to work around this?

by the way, this function is something that mambo does much better. it's crazy that i'm having to screw with php code just to get a contact me form happening.

thanks in advance,
-ryan

fuzzie’s picture

Status: Closed (fixed) » Active

Can you help me with a form here:
http://deibler-insurance.com/node/34

nickels’s picture

I'm using 4.6 - upgrading to 4.7 is not an option.

I want multiple contact forms, each with different recipient emails. Everyone should be able to use these, not just authenticated users. Is there anyway to hide the recipient email address besides this:

#15 submitted by Steven on November 19, 2004 - 20:23

$form .= form_hidden("to", "(INSERT TO: ADDRESS HERE");
$form .= form_hidden("subject", "(INSERT SUBJECT: ADDRESS HERE")");

This should be avoided. It allows anyone to send email using your site and a custom form. It is best to put the to/subject on the server side, and fill it in after the form is submitted. You should also look into throttling, to prevent mass emailing/spamming.

Dries' upcoming Contact.module has such a generic mechanism.

dan_aka_jack’s picture

Hi there,

I've just had a go at re-writing this module for use with Drupal 4.7 if you're interested:

http://drupal.org/node/53543

sodani’s picture

My form submits, but I never get the e-mail. Does anyone know what might be going on? I inserted my e-mail address in settings>form_mail

elv’s picture

Title: form_mail sample. » form_file help needed

I'd like to set up a file upload in a form, but I don't get it. The only help I found was this line "* For assistance with handling the uploaded file correctly, see the API
* provided by file.inc" in zepernick comment.
Hint anynone ? Thanks !

elv’s picture

Title: form_file help needed » form_mail sample

(sorry I changed the title by mistake. Old title is back)

waa’s picture

Title: form_mail sample » Can't seem to get form_mail to honor the $required value

Using the sample php form in this thread, I have set each ofthe fields as required in my form as so:

$form .= form_textfield("Name", "from_name", "", 60, 128, "", "", 1);

Each field name on the form now has a red * next to it signifying that it is indeed a required field, yet I can click "send emai" with all fields empty and form_mail happily shows the "thank you" page and sends off an empty email with the Drupal system's default email as the From: field.

Just in case, I also tried using "1" for the $required value which displayed the red "required" * on the form but results were the same.

Thanks for any help on this.

--
Bill Arlofski
Reverse Polarity

waa’s picture

Title: Can't seem to get form_mail to honor the $required value » form_mail sample

OOps, didn't realize that the title of my post would change the top level title. It's back now... Sorry!