Quantcast
Channel: Free Virtual Servers
Viewing all articles
Browse latest Browse all 37

WYSIWYG Web Site Builder: How do I use PHP to collect form data?

$
0
0

This FAQ relates to the downloadable Easy Internet WYSIWYG Web Builder available from http://www.easyinternetsolutions.co.uk/wsb

  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
  2. Make sure your form contains an editbox with the name 'email'.
  3. Now create a new file using Notepad and call it: feedback.php
  4. Enter the following code into the "feedback.php" file:
    <?php if ($_SERVER['REQUEST_METHOD'] != 'POST'){ header('Refresh: 0; URL=/index.html'); exit; } $mailto = "youremailaddress@example.com"; $subject = "Feedback form"; $message = "Values submitted from web site form:"; $name = Valid_Input($_POST['name']); $email = Valid_Email($_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; } } } $header = "From: ".$name." <".$email.">\n"; $header .= "Reply-To: ".$email."\n"; $header .= "MIME-Version: 1.0\n"; $header .= "Content-Type: text/plain; charset=utf-8\n"; $header .= "Content-Transfer-Encoding: 8bit\n"; $header .= "X-Mailer: PHP v".phpversion(); mail($mailto, $subject, stripslashes($message), $header) or exit('Fatal Mail Error!'); print "Thank you, your message has just been sent."; function Valid_Input($data){ list($data) = preg_split('/\r|\n|%0A|%0D|0x0A|0x0D/i',ltrim($data)); return $data; } function Valid_Email($data){ $pattern = '/^([0-9a-z]([-.\w]*[0-9a-z])*@(([0-9a-z])+([-\w]*[0-9a-z])*\.)+[a-z]{2,6})$/i'; if (preg_match($pattern,$data)){ return $data; } else{ return $GLOBALS['mailto']; } } ?>

    An example file can be downloaded from http://www.easyinternetsolutions.co.uk/wsb/php_form_secure.zip

  5. Replace youremailaddress@example.com with your own email address!
  6. Finally upload feedback.php to your web server.
  7. 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 very few measures against abuse of the form.

    Viewing all articles
    Browse latest Browse all 37

    Trending Articles