Skip to main content
HelenLouise
Inspiring
November 6, 2017
Answered

code to convert .cgi to PHP in form - dreamweaver CS6

  • November 6, 2017
  • 3 replies
  • 2209 views

Hi there,

My form was working fine, I did it some years ago, now get the 404 screen.

My ISP told me .cgi was old, to try PHP.

I've tried to fix it myself and looked around for ideas, but can't manage.

Here are my beginning code for the form:

<form action="http://thatsrightratso.com.au/php-sys/FormMail.cgi" method="post" enctype="application/x-www-form-urlencoded" name="details" id="details">

I will include my final lines of code because now it shows up as errors:

<input type="submit" name="submit" id="submit" value="Please make a personal reading for me!" tabindex="7">

<br>

     <input name="recipient" type="hidden" value="imp@thatsrightratso.com.au">

      <input name="subject" type="hidden" value="Imp reading request">

      <input name="redirect" type="hidden" value="http://www.thatsrightratso.com.au/confirmation.html">

Can you help me?

Thank you

This topic has been closed for replies.
Correct answer Nancy OShea

I haven't used Perl (CGI-bin) scripts for more than a decade.

Below is a responsive contact form built with Bootstrap and PHP code.  Copy & paste into a new, blank document and SaveAs contact.php.

You can read more about how this works in my 3-part tutorial.

Alt-Web Design & Publishing: Responsive Contact Form with Bootstrap and PHP (Part 1)

NOTE:  For this to work, your server must support PHP 5.3 or higher and the PHP mail() function.  If unsure, ask your web hosting provider to confirm your server exceeds these minimum requirements.

<?php

// NOTE: this page must be saved as a .php file.

// And your server must support PHP 5.3+ and php Mail().

// Define variables and set to empty values

$result = $name = $email = $phone = $message = $human = "";

$errName = $errEmail = $errPhone = $errMessage = $errHuman = "";

    if (isset($_POST["submit"])) {

        $name = $_POST['name'];

        $email = $_POST['email'];

        $phone = $_POST['phone'];

        $message = $_POST['message'];

        $human = intval($_POST['human']);

    //valid address on your web server

        $from = 'webmaster@yourdomain.com';

    //your email address where you wish to receive mail

        $to = 'you@yourdomain.com';

        $subject = 'MESSAGE FROM YOUR WEB SITE';

        $headers = "From:$from\r\nReply-to:$email";

        $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message: $message";

// Check if name is entered

if (empty($_POST["name"])) {

$errName = "Please enter your name.";

} else {

    $name = test_input($_POST["name"]);

}

// Check if email is entered

if (empty($_POST["email"])) {

$errEmail = "Please enter your email address.";

} else {

    $email = test_input($_POST["email"]);

    // check if e-mail address is valid format

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

      $errEmail = "Invalid email format.";

    }

}

// Check if phone is entered

if (empty($_POST["phone"])) {

$phone = "";

} else {

    $phone = test_input($_POST["phone"]);

}

//Check if message is entered

if (empty($_POST["message"])) {

$errMessage = "Please enter your message.";

} else {

    $message = test_input($_POST["message"]);

}

//Check if simple anti-bot test is entered

if (empty($_POST["human"])) {

$errHuman = "Please enter the sum.";

} else {

     if ($human !== 12) {

     $errHuman = 'Wrong answer. Please try again.';

        }

}

// If there are no errors, send the email & output results to the form

if (!$errName && !$errEmail && !$errPhone &&  !$errMessage && !$errHuman) {

    if (mail ($to, $subject, $body, $from)) {

        $result='<div class="alert alert-success"><h2><span class="glyphicon glyphicon-ok"></span> Message sent!</h2><h3>Thank you for contacting us. Someone will be in touch with you soon.</h3></div>';

    } else {

        $result='<div class="alert alert-danger"><h2><span class="glyphicon glyphicon-warning-sign"></span> Sorry there was a form processing error.</h2> <h3>Please try again later.</h3></div>';

       }

    }

}

    //sanitize data inputs   

    function test_input($data) {

   $data = trim($data);

   $data = stripslashes($data);

   $data = htmlspecialchars($data);

    $data = (filter_var($data, FILTER_SANITIZE_STRING));

   return $data;

}

//end form processing script

?>

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Contact Form </title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Latest compiled and minified Bootstrap CSS-->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<style>

.required {color:red; font-weight:bold}

.center-block {float:none}

.human {margin: 0 0 0 12px}

</style>

</head>

<body>

<div class="container">

<div class="row">

<div class="col-lg-8 col-lg-offset-2">

<div class="col-md-8 center-block">

<h3>Responsive Contact Form</h3>

<p class="required small">* = Required fields</p>

<!--begin HTML Form-->

<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<!--when submit button is clicked, show results here-->

<div class="form-group">

<div class="col-sm-10 col-sm-offset-2">

<?php echo $result;?>

</div>

</div>

<div class="form-group">

<label for="name" class="col-sm-3 control-label"><span class="required">*</span> Name:</label>

<div class="col-sm-9">

<input type="text" class="form-control" id="name" name="name" placeholder="First & Last" value="<?php echo $name; ?>">

<span class="required small"><?php echo $errName; ?></span>

</div>

</div>

<div class="form-group">

<label for="email" class="col-sm-3 control-label"><span class="required">*</span> Email: </label>

<div class="col-sm-9">

<input type="email" class="form-control" id="email" name="email" placeholder="you@domain.com" value="<?php echo $email; ?>">

<span class="required small"><?php echo $errEmail;?></span>

</div>

</div>

<div class="form-group">

<label for="phone" class="col-sm-3 control-label">Phone: </label>

<div class="col-sm-9">

<input type="tel" class="form-control" id="phone" name="phone" placeholder="(123) 456-7890" value="<?php echo $phone; ?>">

<span class="required small"><?php echo $errPhone;?></span>

</div>

</div>

<div class="form-group">

<label for="message" class="col-sm-3 control-label"><span class="required">*</span> Message:</label>

<div class="col-sm-9">

<textarea class="form-control" rows="4" name="message" id="message" placeholder="Tell us your story"><?php echo $message;?></textarea>

<span class="required small"><?php echo $errMessage;?></span>

</div>

</div>

<div class="form-group">

<label for="human" class="col-sm-3 control-label"><span class="required">*</span> Human Test:</label>

<div class="col-sm-4">

<h3 class="human">6 + 6 = ?</h3>

<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer" value="<?php echo $human; ?>">

<span class="required small"><?php echo $errHuman;?></span>

</div>

</div>

<div class="form-group">

<div class="col-sm-offset-3 col-sm-6 col-sm-offset-3">

<button type="submit" id="submit" name="submit" class="btn-lg btn-primary btn-block">SUBMIT</button>

</div>

</div>

<!--end Form--></form>

<!--end col block--></div>

<!--end col--></div>

<!--end row--></div>

<!--end container--></div>

<!--jQuery 3.2 minified-->

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<!--Bootstrap 3.7 minified-->

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>

</html>

Nancy

3 replies

Participant
January 6, 2018

Hi again,

I've created the 3 required pages for this (https://myphpform.com/final-form.php) however when I download the phpmailer, the autoload file referred to in everyone's install instructions is not there.

I'm pretty lost actually with this, it seems to be way over my head. In the end this isn't even a serious form, it's just a bit of fun on my website. I made the form originally in Dreamweaver CS6 along with the rest of my website of course, so I had no idea about CGI or anything.

I'm not sure what to do.

If a person creates a form in the latest Dreamweaver now, what does it use for it's forms?

Thank you.

Nancy OShea
Community Expert
Community Expert
January 6, 2018

Forms are HTML code.  However, the form processing script will depend on which software you have on your server - PHP, ASP.net, Perl, Python, ColdFusion, etc...

Ask your hosting provider if they have a form-to-email script you can use. 

Failing that, use a service like WooFoo -- Online Form Builder.

Nancy O'Shea— Product User & Community Expert
Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
November 6, 2017

I haven't used Perl (CGI-bin) scripts for more than a decade.

Below is a responsive contact form built with Bootstrap and PHP code.  Copy & paste into a new, blank document and SaveAs contact.php.

You can read more about how this works in my 3-part tutorial.

Alt-Web Design & Publishing: Responsive Contact Form with Bootstrap and PHP (Part 1)

NOTE:  For this to work, your server must support PHP 5.3 or higher and the PHP mail() function.  If unsure, ask your web hosting provider to confirm your server exceeds these minimum requirements.

<?php

// NOTE: this page must be saved as a .php file.

// And your server must support PHP 5.3+ and php Mail().

// Define variables and set to empty values

$result = $name = $email = $phone = $message = $human = "";

$errName = $errEmail = $errPhone = $errMessage = $errHuman = "";

    if (isset($_POST["submit"])) {

        $name = $_POST['name'];

        $email = $_POST['email'];

        $phone = $_POST['phone'];

        $message = $_POST['message'];

        $human = intval($_POST['human']);

    //valid address on your web server

        $from = 'webmaster@yourdomain.com';

    //your email address where you wish to receive mail

        $to = 'you@yourdomain.com';

        $subject = 'MESSAGE FROM YOUR WEB SITE';

        $headers = "From:$from\r\nReply-to:$email";

        $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message: $message";

// Check if name is entered

if (empty($_POST["name"])) {

$errName = "Please enter your name.";

} else {

    $name = test_input($_POST["name"]);

}

// Check if email is entered

if (empty($_POST["email"])) {

$errEmail = "Please enter your email address.";

} else {

    $email = test_input($_POST["email"]);

    // check if e-mail address is valid format

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

      $errEmail = "Invalid email format.";

    }

}

// Check if phone is entered

if (empty($_POST["phone"])) {

$phone = "";

} else {

    $phone = test_input($_POST["phone"]);

}

//Check if message is entered

if (empty($_POST["message"])) {

$errMessage = "Please enter your message.";

} else {

    $message = test_input($_POST["message"]);

}

//Check if simple anti-bot test is entered

if (empty($_POST["human"])) {

$errHuman = "Please enter the sum.";

} else {

     if ($human !== 12) {

     $errHuman = 'Wrong answer. Please try again.';

        }

}

// If there are no errors, send the email & output results to the form

if (!$errName && !$errEmail && !$errPhone &&  !$errMessage && !$errHuman) {

    if (mail ($to, $subject, $body, $from)) {

        $result='<div class="alert alert-success"><h2><span class="glyphicon glyphicon-ok"></span> Message sent!</h2><h3>Thank you for contacting us. Someone will be in touch with you soon.</h3></div>';

    } else {

        $result='<div class="alert alert-danger"><h2><span class="glyphicon glyphicon-warning-sign"></span> Sorry there was a form processing error.</h2> <h3>Please try again later.</h3></div>';

       }

    }

}

    //sanitize data inputs   

    function test_input($data) {

   $data = trim($data);

   $data = stripslashes($data);

   $data = htmlspecialchars($data);

    $data = (filter_var($data, FILTER_SANITIZE_STRING));

   return $data;

}

//end form processing script

?>

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Contact Form </title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Latest compiled and minified Bootstrap CSS-->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<style>

.required {color:red; font-weight:bold}

.center-block {float:none}

.human {margin: 0 0 0 12px}

</style>

</head>

<body>

<div class="container">

<div class="row">

<div class="col-lg-8 col-lg-offset-2">

<div class="col-md-8 center-block">

<h3>Responsive Contact Form</h3>

<p class="required small">* = Required fields</p>

<!--begin HTML Form-->

<form class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<!--when submit button is clicked, show results here-->

<div class="form-group">

<div class="col-sm-10 col-sm-offset-2">

<?php echo $result;?>

</div>

</div>

<div class="form-group">

<label for="name" class="col-sm-3 control-label"><span class="required">*</span> Name:</label>

<div class="col-sm-9">

<input type="text" class="form-control" id="name" name="name" placeholder="First & Last" value="<?php echo $name; ?>">

<span class="required small"><?php echo $errName; ?></span>

</div>

</div>

<div class="form-group">

<label for="email" class="col-sm-3 control-label"><span class="required">*</span> Email: </label>

<div class="col-sm-9">

<input type="email" class="form-control" id="email" name="email" placeholder="you@domain.com" value="<?php echo $email; ?>">

<span class="required small"><?php echo $errEmail;?></span>

</div>

</div>

<div class="form-group">

<label for="phone" class="col-sm-3 control-label">Phone: </label>

<div class="col-sm-9">

<input type="tel" class="form-control" id="phone" name="phone" placeholder="(123) 456-7890" value="<?php echo $phone; ?>">

<span class="required small"><?php echo $errPhone;?></span>

</div>

</div>

<div class="form-group">

<label for="message" class="col-sm-3 control-label"><span class="required">*</span> Message:</label>

<div class="col-sm-9">

<textarea class="form-control" rows="4" name="message" id="message" placeholder="Tell us your story"><?php echo $message;?></textarea>

<span class="required small"><?php echo $errMessage;?></span>

</div>

</div>

<div class="form-group">

<label for="human" class="col-sm-3 control-label"><span class="required">*</span> Human Test:</label>

<div class="col-sm-4">

<h3 class="human">6 + 6 = ?</h3>

<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer" value="<?php echo $human; ?>">

<span class="required small"><?php echo $errHuman;?></span>

</div>

</div>

<div class="form-group">

<div class="col-sm-offset-3 col-sm-6 col-sm-offset-3">

<button type="submit" id="submit" name="submit" class="btn-lg btn-primary btn-block">SUBMIT</button>

</div>

</div>

<!--end Form--></form>

<!--end col block--></div>

<!--end col--></div>

<!--end row--></div>

<!--end container--></div>

<!--jQuery 3.2 minified-->

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<!--Bootstrap 3.7 minified-->

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>

</html>

Nancy

Nancy O'Shea— Product User & Community Expert
HelenLouise
Inspiring
November 7, 2017

Thanks so much Nancy, very helpful.

I'm researching what is best for what I need (and for my capabilities). I really appreciate your help.

B i r n o u
Legend
November 6, 2017

viewing the filenaming, I supose that your CGI was her eto handle a mail sending....

so you'll have to replace the link pointing currently to the CGI to a new and fresh PHP

and there you'll have two choice (not recommanded) but working is to use the mail() PHP function

PHP: mail - Manual

or as a second and more robust choice, PHP mailer GitHub - PHPMailer/PHPMailer: The classic email sending library for PHP  with some niece piece of code and example there Tutorial · PHPMailer/PHPMailer Wiki · GitHub

does this feed your needs ?

HelenLouise
Inspiring
November 6, 2017

Birnou, thank you for your quick response and links.

I will have to have a good look and I will let you know.

I think this may be more difficult than I thought but I will get to the bottom of it!!

B i r n o u
Legend
November 6, 2017

Helen, it's easiest that it seams...

if its so about sending mail... you can decompose the steps

  1. get the field content, in PHP it is really easy... you can do that by getting the name attribute of the field. Now depending on the method used POST or GET, you'll have to store it in a variable
    $name = $_POST['name'] or $_name = $_GET['name']... for the name field
    repeat for all the field used in the mail process
  2. opt for one of the method proposed above... well for testing purpose, use the mail() PHP function
    so once you've got your fields
<?php
     // get all your fields from the form
     // $headers can be optional for testing purpose... you will have to set it depending on your needs
     // all the other variables talk by themselves
    
mail($to, $subject, $message, $headers);
?>