Jump to content

PEAR html_quickform question. *newb*


SteVis

Recommended Posts

I've put together a simple contact form and i'm trying to e-mail the data collected.

 

Code:

<?php

// include the required PEAR class
require_once 'HTML/QuickForm.php';

$form = new HTML_Quickform('contact');

//add the elements
$form->addElement('header', 'contact_header', 'Request a Quote or Information');
$form->addElement('text', 'fname', 'First Name:', 'size="30" maxlength="128"');
$form->addElement('text', 'lname', 'Last Name:', 'size="30" maxlength="128"');
$form->addElement('text', 'email', 'E-Mail:', 'size="30" maxlength="128"');
$form->addElement('text', 'company', 'Company:', 'size="30" maxlength="128"');
$form->addElement('textarea', 'detail', 'Quick description:', 'setrows="15"');
$form->addElement('submit', 'send', 'Submit');

//group the elements to ease the e-mail process


//add some rules
$form->addRule('fname','Please enter your first name','required');
$form->addRule('lname','Please enter your lirst name','required');
$form->addRule('email', 'Please enter a e-mail address', 'required');
$form->addRule('email', 'Please enter a valid E-Mail address', 'email');


//e-mail the form and display a confirmination message
if ($form->validate()) { 
					$form->process('send_message'); 
					} else { 
						$form->display(); } 
						function send_message($data) { 
						mail(me@uber.com','Request information/quote',$data['detail'], $data['email']); 
						echo "Thank you"; 
					}
?>

 

This code works, and it sends the e-mail but I can only get it to send the data from two fields because the mail() only allows 5 parameters or something along those lines. I'm assuming I need to put the form values in an array or something like that but I'm lost on exactly what to do.

Link to comment
Share on other sites

I realize that this probably wasn't the best board for a PEAR problem but for anyone who may have come across this, my solution is here.

 

if ($form->validate()) { 
						$form->freeze();
                            $form->process('send_message'); 
                            } 
						else { 
                                $form->display(); 
							} 

						function send_message($data) 
						{
						$message = array($data['fname'], $data['lname'], $data['email'], $data['message']);
						$str = implode(",", $message);
                            mail('shamilt01@gmail.com','Request information/quote',$str); 
                            echo "Thank you, we will get back to you as soon as possible"; 
                            }

 

I bassically just made an array of the fields (which I should have automated) and imploded the array into a string so I could use the mail() function. Anyway, peace out.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.