Jump to content

D3158

New Members
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

D3158's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks. WIll try it. Also, I don't need to call $_SESSIONS in my submitted-contact.php to make it work also? :\ EDIT: Even though I added session_start(), to my submitted-contact.php file at the very top, it doesn't work. I know it's a lot of code but I'd really appreciate it if you (Langstra) can read the entire thing and provide me with pointers and/or solution on why it doesn't work. It's so bothering me. :|
  2. Basically I've a Contact Form where a user fills in Name, Email Address and Comments and then there is aSubmit button. If I just hit "Submit" without filling in anything or wrong information, it takes me to this page,send_form_email.php. This page has all the validators in it. I want it to sort of (I say sort of because I still need to check whether they input everything correctly) bypass this page and go to "submitted-contact.php" page (it's going to this page but its not showing the following as specified in the 2) where it displays one of the 2 things: 1) Login Success 2) Try Again! Right now, there's nothing showing. :| send_form_email.php has this at the very top and it calls header location to the page, submitted-contact.php SEND_FORM_EMAIL CODE [/b] [b]<?php session_start(); $_SESSION['error']=true; $_SESSION['error']=false; ?> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "blah@hotmail.com"; $email_subject = "Your email subject line here"; function died($error) { // your error code can go here echo $error; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['email']) || !isset($_POST['comments'])) { died(''); } $first_name = $_POST['first_name']; // required $email_from = $_POST['email']; // required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); $sendit= @mail($email_to, $email_subject, $email_message, $headers); if($sendit){ header('Location:submitted-contact.php'); }else{echo "Email failed to send";} } ?> SUBMITTED-CONTACT.PHP CODE <!DOCTYPE html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"><style type="text/css"></style> <title>CKK Internet Marketing</title> <link href="style.css" rel="stylesheet" type="text/css" media="all"> <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lato"> <link rel="shortcut icon" href="images/favicon.ico" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script src="js/jquery.sticky.js"></script> <script src="js/jquery.cycle.all.js"></script> <script src="js/jquery.smoothscroll.js"></script> <script> $(document).ready(function(){ $(".navigation").sticky({topSpacing:0}); }); </script> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-27381915-2']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> <body class="submitted"> <div class="navigation"> <div class="container"> <a href="#"><img src="images/logo.png"</a> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About Us</a></li> <li><a href="/service">Services</a></li> <li><a href="/blog">Blog</a></li> <li><a href="/index.html#contact">Contact</a></li> </ul> </div> </div> <div id="submitted-content-2"> <div class="content container"> <?php if (!isset($_SESSION['flunk'])){ $myString = "MESSAGE FLUNKED!"; echo $myString; }else (!isset($_SESSION['pass'])){ $myString2 = "MESSAGE PASSED!"; ?> <div class="clear"></div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <div class="container"> </div> </div> </body> </html> The php code in submitted-contact.php, the following code is in the right location but just the wrong syntax? <div id="submitted-content-2"> <div class="content container"> <?php if (!isset($_SESSION['flunk'])){ $myString = "MESSAGE FLUNKED!"; echo $myString; }else (!isset($_SESSION['pass'])){ $myString2 = "MESSAGE PASSED!"; ?> <div class="clear"></div> </div> </div> </div> Basically, I want to commute from send_form_email.php to submitted-contact.php one of the two things: 1) If user inputted everything well on the Contact Page, show them, "You're logged in" 2) If user inputted wrong information or did not fill in everything on the Contact Page, show them, "Try Again" I want that to be shown withing my <div class="content container"> Sorry, I know this was a long post but I really could use a hand on this. I have been trying to figure this out for the past couple of days! :| Thanks guys D3158
  3. How would I go about doing it? I have code for them(below) but I am not sure what I am doing wrong. Your help is appreciated! lab6part2menu.php <html> <body> <h1>Content of your reminder file:</h1> <form action="lab6part2decision.php" method="post"> <!--Display content of the reminder file--> <textarea name="content" rows="15" cols ="100%" readonly="readonly"> <?php include "classes.php"; $orgFile = new ModifyFile; $orgFile->loadContent('cronpart2.txt'); $size=$orgFile->countLine(); $orgFile->displayContent(); ?> </textarea><br> Select your options:<br><br> <input type="radio" name="doWhat" value="add" />Add a line<br> <input type="radio" name="doWhat" value="delete" />Delete a line<br> <input type="radio" name="doWhat" value="modify" />Modify a line<br><br> Line No. to Delete/Modify: <select name='chooseLine'> <?php for ($i=0; $i<$size; $i++) { echo "<option value='$i'>$i</option>"; } ?></select> <br><br> <!--if user select add or modify, need to fill in content to work with--> Content to Add/Modify: <?php echo "Hour"; echo "<select name='hour'>"; for ($hour=1; $hour<=24; $hour++) { echo "<option value='$hour'>$hour</option>"; } echo "</select>"; echo "Minute"; echo "<select name='minute'>"; for ($min=0; $min<=59; $min++) { if ($min<10){ echo "<option value='0$min'>$min</option>"; } else { echo "<option value='$min'>$min</option>"; } } echo "</select>"; echo "Day"; echo "<select name='day'>"; for ($day=1; $day<=31; $day++) { echo "<option value='$day'>$day</option>"; } echo "</select>"; echo "Month"; echo "<select name='month'>"; for ($month=1; $month<=12; $month++) { echo "<option value='$month'>$month</option>"; } echo "</select>"; echo "Year"; echo "<input type='text' size='4' maxlength='4' name='year' />"; echo "Email"; echo "<input type='text' name='email' />"; echo "Message"; echo "<input type='text' name='message' />"; ?> <br> <br> <input type="submit" value="Submit" /> <input type="reset" value="Reset" /> </form> lab6part2decision.php <?php if (!isset($_POST["doWhat"])){ die("No selection made.<a href='lab6part2menu.php'>Back</a>"); } $choice=$_POST["doWhat"]; include "classes.php"; $oldFile = new ModFile; $oldFile->loadContent("email.txt"); $oldFile->countLine(); switch ($choice) { case "add": if (!preg_match('/\b\d\d\d\d\b/', trim($_POST['year']))) { die("Year is not valid. <br><a href='lab6part2menu.php'>Back</a>"); } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", trim($_POST['email']))) { die("Email is not valid. <br><a href='lab6part2menu.php'>Back</a>"); } $new=$_POST['hour'].",".$_POST['minute'].",". $_POST['day'].",".$_POST['day'].",".$_POST['month'].",". trim($_POST['year']).",".trim($_POST['email']).",".trim($_POST['message']); $oldFile->addLine($new); $oldFile->countLine(); $oldFile->writeToFile('email.txt'); break; case "delete": $lineToDelete=$_POST["chooseLine"]; $oldFile->deleteLine($lineToDelete); $oldFile->countLine(); $oldFile->writeToFile('email.txt'); break; case "modify": $lineToModify=$_POST["chooseLine"]; if (!preg_match('/\b\d\d\d\d\b/', trim($_POST['year']))) { die("Year is not valid. <br><a href='lab6part2menu.php'>Back</a>"); } if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", trim($_POST['email']))) { die("Email is not valid. <br><a href='lab6part2menu.php'>Back</a>"); } $change=$_POST['hour'].",".$_POST['minute'].",". $_POST['day'].",".$_POST['day'].",".$_POST['month'].",". trim($_POST['year']).",".trim($_POST['email']).",".trim($_POST['message']); $oldFile->modifyLine($lineToModify,$change); $oldFile->countLine(); $oldFile->writeToFile('email.txt'); break; } ?> <html> <head> </head> <body> <h1>Content of your REVISED reminder file:</h1> <form><textarea name='content' rows='20' cols ='100%' readonly='readonly'> <?php $oldFile->countLine(); $oldFile->displayContent(); ?> </textarea></form> <a href="lab6part2menu.php">Back for More Change</a> </body> </html> classes.php <?php class ModifyFile { public $arrayContent; public $endofline; public $size; function ModifyFile () { if (strtoupper(substr(PHP_OS,0,3)=='WIN')) { $this->endofline="\r\n"; } elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) { $endofline="\r"; } else { $endofline="\n"; } //return $endofline; //$endofline="\r\n"; } //open a file to write, from beginning of line function writeToFile($filepath) { $fh=fopen($filepath,'w'); if (!$fh) { die ("error opening file."); } //lock file foreach($arrayContent as $temp) { fwrite($fh,$temp); } //unlock file fclose($fh); } //add a line to content array function addLine($newLine) { $newLine="\r\n".$newLine."\r\n"; return array_push($arrayContent,$newLine); $temp=$size; $temp=$temp-1; $arrayContent[$temp]=$arrayContent[$temp].$endofline; array_push($arrayContent,$newLine); return $arrayContent; } //delete a line from content array function deleteLine($delLine) { //step through each line of the original file for ($i=0; $i<$this->size; $i++) { //only copy line over to another array when line is not the line to delete if ($delLine!=$i) { $modArrayContent[]=$arrayContent[$i]; } } $temp=$size-1; print $temp; if ($modArrayContent[count($modArrayContent)-1]=="") { array_pop($modArrayContent); } $temp=array($arrayContent[$delLine],$endofline, "\r\n", "\r","\n"); //$arrayContent=array_diff($arrayContent, $temp); //print count($arrayContent); return $arrayContent=array_diff($arrayContent, $temp); /*print count($modArrayContent); $arrayContent=$modArrayContent; print count($arrayContent);*/ //return $arrayContent=$modArrayContent; } //modify a line from content array function modifyLine($modLine,$someString) { $size=count($arrayContent); $someString=$someString.$endofline; for ($i=0; $i<$size; $i++) { if ($modLine!=$i) { $modArrayContent[$i]=$arrayContent[$i]; } else { $modArrayContent[$i]=$someString; } } return $arrayContent=$modArrayContent; } //show file content, one line at a time function displayContent() { for($i=0; $i<$this->size; $i++) { print "Line No. " . $i . ": " . $arrayContent[$i]; } } //count number of line in file function countLine() { $size=count($arrayContent); return $this->size; } //load content of txt as an array of lines function loadContent($filepath) { $fh=fopen($filepath,'r'); if (!$fh) { die ("error opening file."); } $count=0; while (!feof($fh)){ $arrayContent[$count] = fgets($fh) ; $count++; } return $arrayContent; } } ?> So basically this is what I see on lab6part2menu.php page. Select your option: Radio button: Add Radio button: Modify Radio button: Delete Line No. to Delete/Modify = dropdown (doesnt have any values to it... I am assuming it's because the content within the table isn't shown which is indicated by line number 1 to 10 or something.. BUT it has this mean thing: <br> <b>Notice</b>: Undefined variable: arrayContent in <b>/home/..../..../..../public_html/..../Lab6/classes.php</b> on line <b>89</b><br/>) Content to Add/Modify = Hrs [Dropdown from 1:00-24:00] Mins[Dropdown from 1:00-59:00] Day [Dropdown from 1-31] Month[Dropdown from 1-12] Year [Whatever year user wants to input] E-mail[Whatever email user wants to input] Message[Whatever message user wants to input] SUBMIT RESET Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.