-
Posts
15 -
Joined
-
Last visited
Profile Information
-
Gender
Male
-
Location
San Francisco, CA
-
Age
48
rad1964's Achievements
Newbie (1/5)
0
Reputation
-
I get the javascript data being written to my initial form page (at the bottom) so it is reading the fields properly, The AJAX, does not yet play a part, please ignore that. In my form tag I have an action="process.php" - what is not happening is the successful.html does not show up, which is called at the bottom of my process.php, which makes me think that the process.php is not being read... Newbie here, in case you couldn't tell. thanks, rad1964
-
Hello, I want to test that the data that is submitted through a form is being captured. And or a succes message is sent. Attached is the form code (grh.html), javascript (grh.js), form processing (process.php), success page (success.html). Basically I am using AJAX to return the form fields that were filled out. When that didn't work, I added the success page which is also not working. Any ideas? Here is my js file contents since the uploader will not upload a .js file.... //AJAX - Creates the XMLHttpRequest that sends a http request to the web server function getXMLHTTP() { var x = false; try { x = new XMLHttpRequest(); } catch(e) { try { x = new ActiveXObject("Microsoft.XMLHTTP"); } catch(ex) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e1) { x = false; } } } return x; } //Retrieves the Forms field values *This is a TEST for diagnostic purposes* function displayFormValues() { var str = ''; var elem = document.getElementById('formGrh').elements; for(var i = 0; i < elem.length; i++) { str += "<b>Name: </b>" + elem.name + " "; str += "<b>Value: </b>" + elem.value + " "; str += "<br />"; } document.getElementById('lblValues').innerHTML = str; } TIA, rad1964 grh.html process.php successful.html
-
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
This works! yea! Thanks for the guidence people! class RadamsAlert { const ALERT_FILE = 'alerts.dat'; function addAlert($alertMessage, $expirationTime){ $alert = array('alert' => $alertMessage, 'expiration' => $expirationTime); $alerts = $this->readAlerts(); $alerts[] = $alert; $this->writeAlerts($alerts); } function readAlerts(){ $alerts = array(); if(file_exists(self::ALERT_FILE)){ $contents = file_get_contents(self::ALERT_FILE); $readAlerts = unserialize($contents); if(count($readAlerts) > 0){ foreach($readAlerts as $alert){ if($alert['expiration'] > time()){ $alerts[] = $alert; } } } } return $alerts; } function writeAlerts(array $alerts){ file_put_contents(self::ALERT_FILE, serialize($alerts)); } } $timedalertsingle = isset($_POST['timedalertsingle']) ? $_POST['timedalertsingle'] : false; $timedalertseconds = isset($_POST['timedalertchoice']) ? (int)$_POST['timedalertchoice'] : 0; $timestamp = time(); if($timedalertsingle !== false && $timedalertseconds > 0){ $radAlert = new RadamsAlert(); $radAlert->addAlert($timedalertsingle, $timedalertseconds + $timestamp); } header('Location: sec.html'); exit(); rad1964 -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
Thanks, I will make an attempt at coding this, then you all can laugh at my code when I post it! bad goto! rad1964 -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
delete me -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
OK, But I am still lost. I am new to this and your solution is aparently above my head because whether it is correct and right does not mean I can interpret it to code. Thats why I do not want to abadon the code I wrote. Because I wrote it, I understand what its doing. (Or is suppoed to do). <pre class="prettyprint"> 1. Read in the file and json_decode() it back into an array </pre> Lets start here... read in the file, - what the heck does that mean? json_decode() -??? <pre class="prettyprint"> 2. Filter out the alerts that have expired </pre> How do we know if they have expired or not. presently most alerts will be manually entered and manually erased. <pre class="prettyprint"> 4. json_encode() the array and write it back into the file </pre> without knowing how steps 1-3 run I have no clue here. <pre class="prettyprint"> 1. Read in the file and json_decode() it back into an array 2. Show the alerts that have not expired </pre> Again without knowing how steps above work, I am clueless for this Sorry for being a dumbass, we all start somewhere rad1964 -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
I will ask again ... why cant PHP tell PHP when PHP is done running a countdown timer... -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
I am sure that would work, but I am wishing I never posted this question. my current alertCheck.php would be useless my single alerts and multiple alerts would also be useless, so this solution while perhaps providing a timing answer, negates what I have already done, thus making it pointless. No offence. -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
The alerts are sent from a secure web page to a web app. When an alert is sent, the web app, when accessed, pops up an alert. There is a secondary field to send an alert which will stack multiple alerts. The only way at present time to remove either a solo alert or stacked alert is to clear all alerts, which overwrites the file with nothing, thus clearing the alert. I now added a timed alert where the admin can send between 1 hour and 48 hours which should expire the alert and overwrite a blank file. On the actual web app I have this javascript: <script type="text/javascript"> $(function() { $.get( "alertCheck.php", function(alertText) { if (alertText != "") { alert(alertText); } }, "text" ); }); </script> on the input side of the timed alert I have this form: <form action="processtime.php" method="post" name="timedalert"> <strong>Post a Timed Alert: </strong><input name="timedalertsingle" size="60" type="text" /><br /> <strong>How many hours this alert will be displayed: </strong> <select name="timedalertchoice" /> <option value=".0833">5 Minutes</option> <option selected="selected" value="1">1 hour</option> <option value="2">2 hours</option> <option value="4">4 hours</option> <option value="6">6 hours</option> <option value="8">8 hours</option> <option value="12">12 hours</option> <option value="18">18 hours</option> <option value="24">24 hours</option> </select> <input name="submit" type="submit" value="submit" /><br /> </form> And finally my processtime.php: <?php $filename = "alertCheck.php"; $timedalertsingle = $_POST['timedalertsingle']; $timedalerthours = $_POST['timedalertchoice']; $timestamp = time(); $timedalertseconds = $timedalerthours * 3600; // Testing the variables echo $timedalertsingle."<br />"; echo $timedalerthours."<br />"; echo $timestamp."<br />"; echo $timedalertseconds."<br />"; echo ($timestamp + $timedalertseconds)."<br />"; // write the file $fp = fopen ($filename, "w"); if ($fp) { fwrite ($fp, $timedalertsingle); fclose ($fp); echo ("<span style='color: #6FF;'>File written:</span> " . " This alert will last for " .$timedalerthours . " Hour(s)" . "<br />"); echo date('m-d-y') ."<br />"; } else { echo ("File was not written"); } // test the time a: if (time() > ($timestamp + $timedalertseconds)){ $fp = fopen ($filename, "w"); if ($fp) { // overwrite the file fwrite ($fp); fclose ($fp); echo ("<span style='color: #6FF;'>There are no alerts.</span> "); } } else { goto a; } ?> rad1964 tia -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
I am having a hard time wrapping my mind around this... no matter if I hide or overwrite file I still need a way to compare the time passed and I can't think of a way to do it with a loop. I am a relative newbie when it comes to PHP. -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
I am trying to use as few resources as possible because I work for a very large compnay and each time I gain access to another level (aka PHP) there seems to be another level I need to take it to (aka database) They have they're own version of chrome browser and are very tight with giving access to stuff. So rather then try and gain CRON or Database access I need to come up with a solution with the tools I have. Is there not a way to calculate this very simple timed equation? -
Write And Erase Contents Of A File After A Length Of Time Has Expired
rad1964 replied to rad1964's topic in PHP Coding Help
a: if (time() > ($timestamp + $timedalertseconds)){ $fp = fopen ($filename, "w"); if ($fp) { // overwrite the file fwrite ($fp); fclose ($fp); echo ("<span style='color: #6FF;'>There are no alerts.</span> "); } } else { goto a; }