can anyone help me with the php code that will allow a form only to be displayed when the page is initially visited and not after the form has been submitted.
php form help
dick220369;10898727 wrote:can anyone help me with the php code that will allow a form only to be displayed when the page is initially visited and not after the form has been submitted.
i don't really know what you wanted to do. The form displaying when you submit it, and before you submit it.
if($_POST[submit]=='boo'){
//no form
}else{
//show form
}
i have the following form which is self referencing meaning that when the details are filled in and submitted the page reloads. i have been asked as part of a uni assignment to implement php code to make the form disappear or be hidden on the page when the page has reloaded and after the data has been submitted.
i can't find any relevant material online that provides any where near a solution to this problem.
<form name="feedbackForm" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="return validation(this);" onsubmit="input.php">
<table cellpadding="10px" width="100%">
<tr>
<td colspan="4" class="required">Items marked (required) must be filled in before the form can be submitted!!!!</td>
</tr>
<tr>
<td>First Name:</td>
<td><input type ="text" size ="30" maxlength ="40" name="firstname"></td>
<td>Surname:</td>
<td><input type="text" Size="30" maxlength="40" name="surname"></td>
</tr>
<tr>
<td>E-mail:<br>(required)</td>
<td><input type="text" Size="30" maxlength="40" name="email"></td>
<td>Comments:<br>(required)</td>
<td><textarea rows="5" cols="50" name="comments"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit"></td>
<td colspan="2"><input type="reset" value="Reset"></td>
</tr>
<tr>
<td>The current time is:</td>
<td id="thetime"></td>
</tr>
<tr>
<td><?php echo "Session start time - server side:";?></td>
<td><?php echo date('H:i');?></td>
</tr>
<tr>
<td>Session start time - client side:</td>
</tr>
</table>
</form>
we really don't like doing your homework, however my example above does address this. you just need to check if the form was posted if so you don't show it, otherwise you do.
cant believe you couldn't find examples on google.
i appreciate the fact that you do not like doing people's homework for them. i'm 39 years of age and like to complete things using my own effort and initiative. however, i have tried unsuccessfully to find any relevant material relating to my porblem. i have tried your suggestion dagon but i cant seem to get it to work. i'm possibly placing it in the wrog part of my code. anyways thanks for the help and i'll endeavour to get it done eventually.
any clearer
if($_POST[submit]=='Submit'){
//process the form submitted
//proberbly output: thank you for filling it in etc
}else{
//show form
//your form code above
}
i have changed my file to reflect the changes suggested but when i run the file i get the following error:
Parse error: syntax error, unexpected '<' in C:\wamp\www\CW4\index.php on line 195
<?php
if ($_POST[submit]=='Submit') {
}else {
<form name="feedbackForm" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="return validation(this);">
<table cellpadding="10px" width="100%">
<tr>
<td colspan="4" class="required">Items marked (required) must be filled in before the form can be submitted!!!!</td>
</tr>
<tr>
<td>First Name:</td>
<td><input type ="text" size ="30" maxlength ="40" name="firstname"></td>
<td>Surname:</td>
<td><input type="text" Size="30" maxlength="40" name="surname"></td>
</tr>
<tr>
<td>E-mail:<br>(required)</td>
<td><input type="text" Size="30" maxlength="40" name="email"></td>
<td>Comments:<br>(required)</td>
<td><textarea rows="5" cols="50" name="comments"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Submit" name="submit"></td>
<td colspan="2"><input type="reset" value="Reset"></td>
</tr>
<tr>
<td>The current time is:</td>
<td id="thetime"></td>
</tr>
<tr>
<td><?php echo "Session start time - server side:";?></td>
<td><?php echo date('H:i');?></td>
</tr>
<tr>
<td>Session start time - client side:</td>
</tr>
</table>
</form>
}
?>
please see this post:http://www.phpbuilder.com/board/showthread.php?t=10316154
and some tutorials on the basics would seem to be a good idea to
http://nz.php.net/manual/en/
whatch this,