UPDATED: How do I use PHP to collect form data?

Frequently Asked Questions about WYSIWYG Web Builder
Locked
User avatar
Pablo
 
Posts: 18453
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

UPDATED: How do I use PHP to collect form data?

Post by Pablo » Tue Jun 21, 2005 7:37 am

These instructions are advanced users only!
Please skip step 2 and continue with 'alternative method' if you would like to implement the 'form processor' in Web Builder.

UPDATE: This article is now also available as a tutorial with screenshots:
http://www.wysiwygwebbuilder.com/forms_php.html

Step 1
Make your form in WYSIWYG Web Builder and change the Form Properties to:
Action: feedback.php
Method: POST
EncodingType: empty, so remove all text

IMPORTANT: Make sure your form contains an editbox with the name 'email'.

Step 2
Now create a new file using Notepad and call it: feedback.php
Enter the following code into the file:

Code: Select all

<?php
  $mailto  = "yourname@yourdomain.com";
  $subject = "Feedback form";
  $message = "Values submitted from web site form:";
  $header  = "From: ".$_POST['email'];
  foreach ($_POST as $key => $value){
    if (!is_array($value)){
      $message .= "\n".$key." : ".$value;
    }
    else{
      foreach ($_POST[$key] as $itemvalue){
        $message .= "\n".$key." : ".$itemvalue;
      }
    }
  }
  mail($mailto, $subject, stripslashes($message), $header);
?>
<HTML>
  <HEAD>
    <TITLE>Thank you for your feedback</TITLE>
  </HEAD>
  <BODY>
    <H2>Thank you for your feedback!</H2>
  </BODY>
</HTML>
Replace yourname@yourdomain.com with your own email address!
Finally upload feedback.php to your web server.

Notes:
- The above php-code can handle multiple selections. That is true for grouped Checkboxes, the Combobox and the Listbox. If you use PHP to handle your form, the items must have names like 'list[]' or 'options[]' (names ending with []).
- The php-script is very basic. Errors are not reported. There are no measures against abuse of the form.

Alternative method (RECOMMEND)
You can also create the feedback page in WYSIWYG Web Builder:
1. Create the 'feedback' page in Web Builder, including some navigation.
2. Open Page Properties and make sure the File Extension is set to PHP!!!
3. Open Page HTML, select Start of Page and enter this code:

Code: Select all

<?php
  $mailto  = "yourname@yourdomain.com";
  $subject = "Feedback form";
  $message = "Values submitted from web site form:";
  $header  = "From: ".$_POST['email'];
  foreach ($_POST as $key => $value){
    if (!is_array($value)){
      $message .= "\n".$key." : ".$value;
    }
    else{
      foreach ($_POST[$key] as $itemvalue){
        $message .= "\n".$key." : ".$itemvalue;
      }
    }
  }
  mail($mailto, $subject, stripslashes($message), $header);
?>
Download the example here:
http://www.wysiwygwebbuilder.com/support/php_form.zip

Special thanks to Kees!

Locked

Who is online

Users browsing this forum: No registered users and 3 guests