Forum Moderators: coopster
I'm currently trying to implement Securimage captcha into a webpage, I've got it working with my standard contact form perfectly. The issues start when I incorporate checkboxes and specifically when the checkboxes are not selected and the form is sent.
For every unselected checkbox i'm getting errors like these:
Notice: Undefined index: category1 in /home/content/p/r/o/prop/html/reviewform.php on line 18
Notice: Undefined index: category2 in /home/content/p/r/o/prop/html/reviewform.php on line 18
Notice: Undefined index: category3
in /home/content/p/r/o/prop/html/reviewform.php on line 18
From what I gather, I need to use some kind of if/else statement but i'm not sure what to do from here?
this is the code in my form page:
<img id="captcha" src="/testing/securimage/securimage_show.php" alt="CAPTCHA Image" />
<br />
<input type="text" name="captcha_code" size="10" maxlength="6" />
a href="#" onclick="document.getElementById('captcha').src = '/testing/securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
and here's my process php page
<?php session_start(); ?>
<?php error_reporting(E_ALL); ini_set('display_errors', 'on'); ?>
<?php
include_once $_SERVER['DOCUMENT_ROOT'].'/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
die('The code you entered was incorrect. Go back and try again.');
}
?>
<?php
$to = "email@host.com" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from";
$subject = "Website - Form Data";
$fields = array();
$fields{"name"} = "name";
$fields{"number"} = "number";
$fields{"email"} = "email";
$fields{"category1"} = "category1";
$fields{"category2"} = "category2";
$fields{"category3"} = "category3";
$fields{"category4"} = "category4";
$fields{"message"} = "message";
$body = "The website received the following form submission:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: noreply@host.com.au";
$subject2 = "Thanks for the message";
$autoreply = "Autoreply Message";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: form_return.php" );}
else
{print "We encountered an error sending your mail, please retry"; }
}
}
if anyone one could help it would be greatly appreciated.
if (isset($_POST['category1 '])) {
// do something
}
dc