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([email protected]','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
https://forums.phpfreaks.com/topic/96316-pear-html_quickform-question-newb/
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('[email protected]','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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.