Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need any user to submit a form and dont show it to anyone else after being submitted

Posted on 2006-10-25
5
Medium Priority
?
185 Views
Last Modified: 2012-05-05
I have a page that shows up as an error page on my website  if the db cant connect.

I added the following to the page. This provides a form to a user to alert the admin that the site is down (works with sms) I will place a notice like" you are the first to see this erorror please advise the site admin"  

Then once theyve submitted it to me I dont want it to show up to anyone else.

I was thinking on the form submit to set a variable to 1 and later check the variable if its 1 I will not show the form code otherwise I will.

I have no clue as to how to make this work any thoughts Do I simply

define $count as global

then set
 
$count = 1; in the code that transmits the sms? Will this hold that variable no matter how many times the page is loaded?

Thanks



<form method="POST" action="<?php echo $PHP_SELF; ?>">
Number:<br />
<input type="text" name="number" maxlength="10" class="inputbox"><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type="text" name="subject" maxlength="20" class="inputbox"><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name="message" rows="10" cols="15" class="inputbox"></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type="submit" name="do" value="Send" class="button">
</form>
0
Comment
Question by:Roba122
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 4

Expert Comment

by:anilande
ID: 17809800
if u want to retain a value after submitting the form use
$_SESSION['hit']=1;

this value will be retained in the server/session until the session is not destroyed.

to know about details about sessions visit this link

http://in.php.net/session
0
 
LVL 16

Expert Comment

by:ellandrd
ID: 17810639
you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php'

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>"
}
?>
0
 
LVL 16

Accepted Solution

by:
ellandrd earned 2000 total points
ID: 17810715
There was an error in my last post, please find proper code below!!


you could write your data to a text file on the server, so that the solution is independant of any sessions for example.  You should make sure that you have the proper write/execute permissions on the server.  If you prefer, instead of posting form data to $_SERVER[PHP_SELF], you could post form data to a file in a section of your server that is not accessable from the web, this will remove any dangers of setting write permissions to web accessible folders.

in your section for handling the sms sending, you need to add the following code prior to the sms sending, which will write a small text file in the same directory as the script.  By writing the data in a php format, we can use it later if you want to make your script more advanced (reset button?)

<?php
$your_data = "$smssent=1";
// Open the file and erase the contents if any
$fp = fopen("smssent.php", "w");
// Write the data to the file
fwrite($fp, $your_data);
// Close the file
fclose($fp);
?>

You then need to use the following code on your main error page, which will decide whether or not to show your form, based on whether or not the file exists.  If you want to add reset scripts etc, you can always check the data that is held in the "$smssent" variable instead.

<?php
$filename='smssent.php';

if (file_exists($filename)) {
   //Nothing needs to be done, we don't want to show the form
}
else {
echo "<form method='POST' action='$PHP_SELF'>
Number:<br />
<input type='text' name='number' maxlength='10' class='inputbox'><br />
(Example: 8001234567; US Only)<br /><br />
Subject:<br />
<input type='text' name='subject' maxlength='20' class='inputbox'><br />
(Max 20 Characters)<br /><br />
Message:<br />
<textarea name='message' rows='10' cols='15' class='inputbox'></textarea><br />
(Between 3 - 120 Characters)<br /><br />
<input type='submit' name='do' value='Send' class='button'>
</form>";
}
?>
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question