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
178 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now