Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread Red Wingate
Nice one here, got some class for this type of handling as well but it
will also do some nice magic when it comes to checking for valid data
or displaying the input again for validation :-)

My way to go:
1. Display the form
2. Check all required fields (name start with req_)
2.1 ( ok ) Parse page and display input instead of fields
2.2 ( fail ) Parse page and display form again with values inserted
3. Send the E-Mail

[...]
 Here is a class I use with my template system but it is easy to modify
 it.
[...]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread John W. Holmes
From: Tom Rogers [EMAIL PROTECTED]
 JWH Does anyone know of a script that'll receive the results of a form,
 JWH parse the original form and substitute the user supplied data in for
the
 JWH form elements and then send an HTML email of the form?

 Here is a class I use with my template system but it is easy to modify
 it.

Thanks for the tip. This requires you know what the elements of the form
are, though. Like I said, if you know what's in the form, this whole process
is pretty trivial.

I want to take an unknown form, receive the data, then redisplay the form
with the form elements gone and the values submitted replacing them. My
personal needs incorporate sending this in an email, but that's the easy
part.

input, select and textarea elements will be easy, I think. You can
just replace the whole element with a post variable matching it's name.

$page = preg_replace('/input type=text
name=([^]+)[^]+/ie','$_POST[\'\1\']',$page);

The checkboxes and radio buttons would be a little harder.

input type=checkbox name=foo value=1
input type=checkbox name=foo value=2

I'm thinking this will take two passes. First match the names of each
checkbox or radio button. Once I have the $name, I can say

$_POST[$name][$_POST[$name]] = $_POST[$name];

resulting in

$_POST['foo']['1'] = 1

if the first checkbox was selected.

Then, do a replace

$page = preg_replace('/input type=checkbox name=([^]+)
value=([^]+)[^]+/ie','$_POST[\'\1\'][\'\2\']',$page);

Accounting for arrays would require something else and I'd obviously have to
account for extra attributes within the form elements. Anybody thing of
something that's more efficient? I'm still just brainstorming here. :)

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[2]: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread Tom Rogers
Hi,

Tuesday, April 20, 2004, 11:29:41 PM, you wrote:
JWH From: Tom Rogers [EMAIL PROTECTED]
 JWH Does anyone know of a script that'll receive the results of a form,
 JWH parse the original form and substitute the user supplied data in for
JWH the
 JWH form elements and then send an HTML email of the form?

 Here is a class I use with my template system but it is easy to modify
 it.

JWH Thanks for the tip. This requires you know what the elements of the form
JWH are, though. Like I said, if you know what's in the form, this whole process
JWH is pretty trivial.

JWH I want to take an unknown form, receive the data, then redisplay the form
JWH with the form elements gone and the values submitted replacing them. My
JWH personal needs incorporate sending this in an email, but that's the easy
JWH part.

JWH input, select and textarea elements will be easy, I think. You can
JWH just replace the whole element with a post variable matching it's name.

JWH $page = preg_replace('/input type=text
name=([^]+)[^]+/ie','$_POST[\'\1\']',$page);

JWH The checkboxes and radio buttons would be a little harder.

JWH input type=checkbox name=foo value=1
JWH input type=checkbox name=foo value=2

JWH I'm thinking this will take two passes. First match the names of each
JWH checkbox or radio button. Once I have the $name, I can say

JWH $_POST[$name][$_POST[$name]] = $_POST[$name];

JWH resulting in

JWH $_POST['foo']['1'] = 1

JWH if the first checkbox was selected.

JWH Then, do a replace

JWH $page = preg_replace('/input type=checkbox name=([^]+)
value=([^]+)[^]+/ie','$_POST[\'\1\'][\'\2\']',$page);

JWH Accounting for arrays would require something else and I'd obviously have to
JWH account for extra attributes within the form elements. Anybody thing of
JWH something that's more efficient? I'm still just brainstorming here. :)

JWH ---John Holmes...


It does not need to know the form elements, only the reserved words it
uses and you take those out and pass them directly to the class if
needed. It takes the variable name from the POST array and uses it with
the value. No need to know what the input fields are called or even
what type - checkboxes and radio groups work fine.

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re[2]: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread John W. Holmes
From: Tom Rogers [EMAIL PROTECTED]

 It does not need to know the form elements, only the reserved words it
 uses and you take those out and pass them directly to the class if
 needed. It takes the variable name from the POST array and uses it with
 the value. No need to know what the input fields are called or even
 what type - checkboxes and radio groups work fine.

Okay, I see what you mean.

default:  //not a keyword
$k = ereg_replace(_, ,$k);  //get rid of _ and replace with a space
if($v == BR){  //if BR add a carriage return,used for making blank line
  $this-vars['blocks']['submit'][$x]['ifs']['break'] = 'nbsp;';
  $this-text .= \n;
}else{
  $this-vars['blocks']['submit'][$x]['vars']['name'] = $k;
  $this-vars['blocks']['submit'][$x]['vars']['value'] = $v;
  $this-text .= $k : $v\n;  //add the variable name and value to email
 }

I see what you're doing here, but it doesn't fit what I'm looking for
exactly. You just create a Key : Value list to include in the email. I want
the email to look exactly like the form, only substitute in the values
submitted by the user.

---John Holmes...

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re[4]: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread Tom Rogers
Hi,

Wednesday, April 21, 2004, 12:05:08 AM, you wrote:
JWH I see what you're doing here, but it doesn't fit what I'm looking for
JWH exactly. You just create a Key : Value list to include in the email. I want
JWH the email to look exactly like the form, only substitute in the values
JWH submitted by the user.

JWH ---John Holmes...

Now I see what you want, the real problem would be select boxes and
radio buttons, the others would be quite easy. looks like a job for
preg_replace_callback() and the worlds ugliest case statement:-)
Have you got a good sample form I could play with? It would be quite a
class. I assume you have access to the original form :)

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re[4]: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-20 Thread Justin French
On 21/04/2004, at 12:18 AM, Tom Rogers wrote:

Now I see what you want, the real problem would be select boxes and
radio buttons, the others would be quite easy. looks like a job for
preg_replace_callback() and the worlds ugliest case statement:-)
Have you got a good sample form I could play with? It would be quite a
class. I assume you have access to the original form :)
No, he wants it to work with ANY form :)

---
Justin French
http://indent.com.au
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-19 Thread John W. Holmes
Does anyone know of a script that'll receive the results of a form, 
parse the original form and substitute the user supplied data in for the 
form elements and then send an HTML email of the form?

For a static form, this obviously isn't too hard, but it'd be ideal if 
the program was dynamic enough to work with any kind of form.

Let me know if you've heard of anything. If not... well, I guess it's 
writin' time! ;)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-19 Thread John W. Holmes
Justin French wrote:
But I guess your motivation behind starting with the HTML is so that Joe 
Average can build a form in a WYSIWYG editor without caring about 
anything else, right?
Yeah, that's the key. It'd be easy if I could just build everything from 
an XML file.

I'm thinking that if I just parsed the HTML form looking for input * 
name=* *, match the name and replace the whole thing with 
$_POST['name'] and then continue on with other form elements in a 
similar matter. Skip over buttons, image maps, etc...

Just brainstorming right now... :)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Program that'll parse HTML form with results and send HTML email?

2004-04-19 Thread Tom Rogers
Hi,

Tuesday, April 20, 2004, 11:10:24 AM, you wrote:
JWH Does anyone know of a script that'll receive the results of a form,
JWH parse the original form and substitute the user supplied data in for the
JWH form elements and then send an HTML email of the form?

JWH For a static form, this obviously isn't too hard, but it'd be ideal if
JWH the program was dynamic enough to work with any kind of form.

JWH Let me know if you've heard of anything. If not... well, I guess it's
JWH writin' time! ;)

JWH -- 
JWH ---John Holmes...

JWH Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

JWH php|architect: The Magazine for PHP Professionals – www.phparch.com

Here is a class I use with my template system but it is easy to modify
it.

//class
class doFormsClass {
var $text = '';
var $vars = array();
var $emailto = '';
function doFormsClass(){
if($this-emailto = req::request('EmailTo',false)){
$today = Date(d/m/Y H:i:s);
$this-text = Form submitted on $today\n\n;   
//$text holds the email message
$this-vars['vars']['header'] = 'Form submitted on '.$today;
$x = 0;
while (list($k, $v)=each($_POST)) { //loop through 
all the variables sent
switch($k){
 //and break on keywords 
case(EmailTo):
$this-vars['vars']['mailto'] = $v;
break;
//these we don't want in the email
case 'Quiet':
case 'PHPSESSID':
case 'Email2':
case 'FormBackground':
case 'FormBottomMessage':
case 'FormTopMessage':
case 'FormSubject':
case 'FormRedirect':
case 'submit':
case 'MAIL':
break;
default:   
 //not a keyword
$k = ereg_replace(_, ,$k);  //get 
rid of _ and replace with a space
if($v == BR){
 //if BR add a carriage return,used for making 
blank line

$this-vars['blocks']['submit'][$x]['ifs']['break'] = 'nbsp;';
$this-text .= \n;
}else{

$this-vars['blocks']['submit'][$x]['vars']['name'] = $k;

$this-vars['blocks']['submit'][$x]['vars']['value'] = $v;
$this-text .= $k : $v\n;
 //add the variable name and value to email
}
$x++;
break;
}
}
}
if(isset($_POST['FormSubject'])){
$subject = $_POST['FormSubject'];
}else{
$subject = Form submitted $today;
}
$this-vars['vars']['subject'] = $subject;
if(isset($_POST['Email']) || isset($_POST['email'])){
if(isset($_POST['Email'])):
$tail = FROM: .$_POST['Email'];
else:
$tail = FROM: .$_POST['email'];
endif;
}
else{
$tail = FROM: Unknown;
}
mail($_POST['EmailTo'],$subject,$this-text,$tail); //send 
the email
if(isset($_POST['Email2'])){
mail($_POST['Email2'],$subject,$text,$tail);//send CC if 
needed
}
}
function getVars(){
return $this-vars;
}
}



usage
if($form_submitted){
  $df = new doFormsClass();
  $vars = $df-getVars();
  print_r($vars); // use for the template
}

Sample form

form method=post action=? echo $_SERVER['PHP_SELF']?
  !--