Search the Community
Showing results for tags 'sticky field'.
-
This is my code and what i need is the form to do the following: validate the data with simple regex expressions sticky fields if the user hits submit and the field is not valid or filled out report back to the screen below the form in red once the form is completed and meets validation email it to email address, which will be a static variable i need to attach the ip of the current machine [have not implemented this yet bc of current issues] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" > <head> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Form Styling!</title> </head> <body> <h2>Firewall Request Form</h2> <?php $date = date('l F j, o g:i:s a'); if ($_POST['fr_submit']){ checkFields(); $fr_sd_ip = $_POST['fr_sd_ip']; $fr_sd_port = $_POST['fr_sd_port']; $fr_protocol = $_POST['fr_protocol']; $fr_sd_app = $_POST['fr_sd_app']; $fr_reason = $_POST['fr_reason']; $fr_email = $_POST['fr_email']; $errortest = "This is not set"; $email_to = "some@destination.com"; $email_body = "Description: " + $_POST['fr_reason'] + "Source/Dest. IP: " + $_POST['fr_sd_ip'] + "Port: " + $_POST['fr_sd_port'] + "Protocol: " + $_POST['fr_protocol'] + "Application: " + $_POST['fr_sd_app'] + "Description/Reason: " + $_POST['fr_reason'] + "User/Email: " + $_POST['fr_email']; mail($email_to, $fr_sd_app, $email_body, 'From: ' . $fr_email); } elseif (!isset($_POST['fr_sd_ip']) or !isset($_POST['fr_sd_port']) or !isset($_POST['fr_protocol']) or !isset($_POST['fr_sd_app']) or !isset($_POST['fr_reason']) or !isset($_POST['fr_email'])){ //fieldnotset(); echo $errortest; } //error module function died($error) { echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } //section for field validation function checkFields(){ $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; $fr_sd_ip = $_POST['fr_sd_ip']; $fr_sd_port = $_POST['fr_sd_port']; $fr_protocol = $_POST['fr_protocol']; $fr_sd_app = $_POST['fr_sd_app']; $fr_reason = $_POST['fr_reason']; $fr_email = $_POST['fr_email']; if(!preg_match($email_exp, $fr_email) && isset($fr_email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } if(!preg_match('/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'. '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'. '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.'. '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/', $fr_sd_ip) && isset($fr_sd_ip)){ $error_message .= 'The IP address you have entered is not valid.'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(strlen($fr_reason) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } } function fieldnotset(){ if (!isset($fr_sd_ip) && empty($fr_sd_ip)){ $error = "Please fill out the source/destiantion IP address."; } if (!isset($fr_sd_port) && empty($fr_sd_port)){ $error = "Please fill out the source/destiantion port."; } if (!isset($fr_protocol) && empty($fr_protocol)){ $error = "Please fill out the protocol required(i.e. TCP...UDP)."; } if (!isset($fr_sd_app) && empty($fr_sd_app)){ $error = "Please fill out the source/destiantion application."; } if (!isset($fr_reason) && empty($fr_reason)){ $error = "Please fill out the reason/description box"; } if (!isset($fr_email) && empty($fr_email)){ $error = "Please fill out the username/email"; } } /*function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); }*/ ?> <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post"> <!-- This form is setup to allow the user to request changes to the firewall with requirements needed outlined in the form below. Fields needed are: Description, Source/Dest. port,Source/Dest. ip, Source/Dest. Application, Protocol (i.e. TCP, UDP, etc.), Username/Email --> <!-- <tr> <td valign="top"> <label for="fr_sd_ip">Source/Dest. IP Address:</label> </td> <td valign="top"> <input type="text" name="fr_sd_ip" maxlength="30" size="20"> </td> </tr> --> <table width="375px"> <tr> <td valign="top"> <label for="fr_sd_ip">Source/Dest. IP Address: *</label> </td> <td valign="top"> <input type="text" name="fr_sd_ip" maxlength="30" size="20" value="<?php echo htmlentities($_POST['fr_sd_ip']) ?>"> </td> </tr> <tr> <td valign="top"> <label for="fr_sd_port">Source/Dest. Port: *</label> </td> <td valign="top"> <input type="text" name="fr_sd_port" maxlength="30" size="20" value="<?php echo htmlentities($_POST['fr_sd_port']) ?>"> </td> </tr> <tr> <td valign="top"> <label for="fr_protocol">Protocol: *</label> </td> <td valign="top"> <input type="text" name="fr_protocol" maxlength="30" size="20" value="<?php echo htmlentities($_POST['fr_protocol']) ?>"> </td> </tr> <tr> <td valign="top"> <label for="fr_sd_app">Application: *</label> </td> <td valign="top"> <input type="text" name="fr_sd_app" maxlength="30" size="20" value="<?php echo htmlentities($_POST['fr_sd_app']) ?>"> </td> </tr> <tr> <td valign="top"> <label for="fr_reason">Description/Reason: *</label> </td> <td valign="top"> <textarea name="fr_reason" maxlength="500" cols="19" rows="8" > <?php echo htmlentities($_POST['fr_reason']) ?></textarea> </td> </tr> <tr> <td valign="top"> <label for="fr_email">Username/Email: *</label> </td> <td valign="top"> <input type="text" name="fr_email" maxlength="30" size="20" value="<?php echo htmlentities($_POST['fr_email']) ?>"> </td> </tr> </table> <input type="submit" name="fr_submit" value="Email Firewall Request"> </form> </br> <?php echo "\r\nToday is: $date"; ?> </body> </html> This is my most updated php form, i have had the form working basically without any validation. Atm it does not validate any information, it does utilize sticky fields, emailing doesn't work now with the modified variable i pass it, and the regex expressions are incomplete bc i cannot figure out the current issues. I have attached a picture of the form web page if anyone wants to see it(its plain but that's all i basically need).
- 21 replies
-
- sticky
- field validation
-
(and 2 more)
Tagged with: