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
180 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 500 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

705 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