dazzclub Posted September 8, 2009 Share Posted September 8, 2009 Hi there, I am testing my form so when i press submit i get several variables being displayed as Notice: Undefined index: variable name here I looked at to see if the spelling is right so to rule any further complications these variables now use lower case had include no special characters. These variables are checkboxes on my form.. to see it live visit http://www.lcrhallcrest.com/education.php Here is the actual code function sample_pack() { //$mail=ini_set(SMTP,"smtp.orange.co.uk"); //$mail=ini_set(smtp_port,25); $success =''; $fail = ''; $Error_Name = ''; $ErrorTel = ''; $ErrorEmail = ''; //this will check to see if the form has been completed accordingly if(isset($_POST['submitted'])) { // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $company_name = $contact_name = $tel_number = $email_address = $address = $address_two = $postcode = $city = $conductivitybars = $inks = $lcsheets = $radiationdiscs = $thermometers = FALSE; // Check for a first name: if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['company_name'])) { $company_name = addslashes ($trimmed['company_name']); } if (preg_match ('/^[A-Z \'.-]{2,60}$/i', $trimmed['contact_name'])) { $contact_name = addslashes ($trimmed['contact_name']); } else { $Error_Name = '<strong class="Error">Please enter a contact name</strong>'; } if ($tel_number= ereg_replace("[^0-9]", "", $trimmed['tel_number'])) { $tel_number = addslashes ($trimmed['tel_number']); } else { $ErrorTel = '<strong class="Error">Please enter your telephone number</strong>'; } // Check for an email address: if (preg_match ('/^[\w.-]+@[\w.-]+\.[A-Za-z]{2,6}$/', $trimmed['email_address'])) { $email_address = addslashes ( $trimmed['email_address']); } else { $ErrorEmail = '<strong class="Error">Please enter a valid email address</strong>'; } if (preg_match ('/^[A-Z \'.-0|1|2|3|4|5|6|7|8|9]{2,20}$/i', $trimmed['address'])) { $address = addslashes ($trimmed['address']); } else { $address = 'FALSE'; } if (preg_match ('/^[A-Z \'.-0|1|2|3|4|5|6|7|8|9]{2,20}$/i', $trimmed['address_two'])) { $address_two = addslashes ($trimmed['address_two']); } else { $address_two = 'FALSE'; } if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['city'])) { $city = addslashes ($trimmed['city']); } else { $city = 'FALSE'; } if (preg_match ('/^[A-Z \'.-0|1|2|3|4|5|6|7|8|9]{2,20}$/i', $trimmed['postcode'])) { $postcode = addslashes ($trimmed['postcode']); } else { $postcode = 'FALSE'; } //product checkboxes if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['conductivitybars'])) { $conductivitybars = addslashes($trimmed['conductivitybars']); } else { $conductivitybars = 'no'; } if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['inks'])) { $inks = addslashes($trimmed['inks']); } else { $inks= 'no'; } if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['lcsheets'])) { $lcsheets = addslashes($trimmed['lcSheets']); } else { $lcsheets= 'no'; } if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['radiationdiscs'])) { $radiationdiscs = addslashes($trimmed['radiationdiscs']); } else { $radiationdiscs= 'no'; } if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['thermometers'])) { $thermometers = addslashes($trimmed['thermometers']); } else { $thermometers= 'no'; } //addiotional check boxes if ($company_name && $contact_name && $tel_number && $email_address && $address && $address_two && $city && $postcode && $conductivitybars && $inks && $lcsheets && $radiationdiscs && $thermometers ) { // If everything's OK... //insert into database //$q = "INSERT INTO enquiries (first_name, last_name, email, title, company, address_1, address_2, post_code, city, state, country, tel, comments, enquiry_date) VALUES ('$first_name', '$last_name', '$email', '$title', '$company', '$address_1','$address_2', '$post_code','$city', '$state', '$country', '$tel', '$comments', NOW() )"; //$r = mysqli_query ($dbc, $q) or 'insert failed something messed up'; //if (mysqli_affected_rows($dbc) == 1) { { //send mail $headers = "From: LCR Hallcrest \n "; $headers .= " \r\n"; $headers .= "Reply-To: no-replay@lcrhallcrest.com \r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $body = "Dear <strong>$contact_name</strong> <br /> <br /> We are happy you have spent some time completing our sample pack form. <br /> <br /> Visit <a href=\"http://www.lcrhallcrest.com\" title=\"temperature Sensitive applications\">http://www.lcrhallcrest.com</a> for Temperature Sensitive applications. <br /> <br /> <a href=\"mailto:myemail\" target=\"_blank\" class\"enquiry\">Admin@lcrhallcrest.com</a><br /> <span style=\"font-size:8pt;\">Worlds Largest Producer of Colour Changing Temperature Sensitive - Indicating Graphic Devices and Materials</span> \n\n"; mail($trimmed['email_address'], 'Thank you for visiting LCR Hallcrest', $body, $headers); //finish the page //send enquiry to admin as well //send email aswell $sendTo = "myemail"; $subject = "Thermosmart Sample Pack Request"; $headers = "From:From \n "; $headers .= " $contact_name \r\n"; $headers .= " BCC: myemail \r\n"; $headers .= "Reply-To: no-replay@lcrhallcrest.com\r\n"; $headers .= "MIME-Version: 1.0\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\n"; $message ="Hi Linda,<br /> <br /> This email is to inform you that <span style=\"font-weight:bold;\">$contact_name</span> made a sample request.<br /> <br /> <br /> <p>Company: <strong>$company_name</strong></p> <p>Address:<br/> <strong> $address<br /> $address_two<br /> $city<br /> $postcode </strong> </p> <p>tel: <strong>$tel_number</strong></p> <p>email: <strong><a href=\"mailto:$email_address\">$email_address</a></strong></p> <p>Contact name: <strong>$contact_name</strong></p> <p><strong>Requested sample pack</strong>:</p> <p>conductivity bars: <strong>$conductivitybars</strong></p> <p>inks: <strong>$inks</strong></p> <p>lc Sheets: <strong>$lcsheets</strong></p> <p>radiation discs: <strong>$radiationdiscs</strong></p> <p>thermometers: <strong>$thermometers</strong></p> <br /> <br /> From<br /> <a href=\"mailto:myemail\" target=\"_blank\" class\"enquiry\">Admin@lcrhallcrest.com</a><br /> <span style=\"font-size:7pt;\">LCR Hallcrest</span>"; mail($sendTo, $subject, $message, $headers); } $success = "<strong class=\"success\">Thank you <strong>$contact_name</strong> for your enquiry!!</strong>"; // Stop the page. } else { // If it did not run OK. $fail = '<strong id="fail">Can you make sure the required fields have been completed.</strong>'; } } echo ' <form method="post" action="education.php" class="sample_pack"> '.$success.''.$fail.' <fieldset> <legend>Complete form for sample pack</legend> <strong class="required_field">*Required field</strong> <p><label for="company_name">Company Name</label><input type="text" name="company_name" id="company_name" tabindex="1" value=""></p> <p><label for="contact_name" ><span>required</span>'.$Error_Name.'Contact Name</label><input type="text" name="contact_name" id="contact_name" tabindex="2" id="name"></p> <p><label for="tel_number"><span>required</span>'.$ErrorTel.'Tel Number</label><input type="text" name="tel_number" id="tel_number" tabindex="3"></p> <p><label for="email_address"><span>required</span>'.$ErrorEmail.'Email</label><input type="text" name="email_address" id="email_address" tabindex="4"></p> <p><label for="address"><span>required</span>Address</label> <input type="text" name="address" id="address" tabindex="5"></p> <p><label for="address_two"><span>required</span>Address 2</label><input type="text" name="address_two" id="address_two" tabindex="6"></p> <p><label for="city">City</label> <input type="text" name="city" id="city" tabindex="7"></p> <p><label for="postcode"><span>required</span>Postcode</label><input type="text" name="postcode" id="postcode" tabindex="8"></p> </fieldset> <fieldset class="packs"> <legend>Request a sample pack</legend> <ul> <li><input type="checkbox" name="conductivitybars" id="conductivitybars" value="yes" tabindex="9" /><label for="conductivityBars">Conductivity bars</label></li> <li><input type="checkbox" name="inks" id="inks" value="yes" tabindex="10" /><label for="inks">ink</label></li> <li><input type="checkbox" name="lcsheets" id="lcsheets" value="yes" tabindex="11" /><label for="lcsheets">lc sheets</label></li> <li><input type="checkbox" name="radiationdiscs" id="radiationdiscs" value="yes" tabindex="12" /><label for="radiationdiscs">radiation discs</label></li> <li><input type="checkbox" name="thermometers" id="thermometers" value="yes" tabindex="13" /><label for="thermometers">thermometers</label></li> </ul> <p><input type="submit" value="submit" name="submit" tabindex="14"/> <input type="hidden" name="submitted" value="TRUE" /></p> </fieldset> </form>'; } [code] Any help would be great.. Thanks Darren Quote Link to comment https://forums.phpfreaks.com/topic/173513-notice-undefined-index/ Share on other sites More sharing options...
RichardRotterdam Posted September 8, 2009 Share Posted September 8, 2009 Is this one of the lines that produces the error? if (preg_match ('/^[A-Z \'.-]{2,20}$/i', $trimmed['conductivitybars'])) { Here you are probably requesting a value from the array where the index 'conductivitybars' doesn't exist. in code. you need to set the index before you can use it. for example this will not give a notice message: $trimmed = array(); $trimmed['conductivitybars'] = ""; echo $trimmed['conductivitybars']; this will give the notice message: $trimmed = array(); // without the 'conductivitybars' index set echo $trimmed['conductivitybars']; Quote Link to comment https://forums.phpfreaks.com/topic/173513-notice-undefined-index/#findComment-914628 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.