Log in

View Full Version : Obligatory Form



dog
11-24-2006, 05:07 PM
Hello. Firstly, I'm very, very, very new to PHP and not certain it's what i need for this, so please feel free to point me to a better section of the forums if that's appropriate.

I want to make a page that has an obligatory form infront of it. i.e. when you access the page a form pops up in front, and you have to fill out the form to make it close.

I don't want users to have to do this everytime they access the page. Just once.

How can I make the form obligatory? How will it know if it has been filled out completely or not? Perhaps someone could point me to some examples.

And secondly what do I need to do to have the website remember when the user correctly fills out the form and not show them the form in future.

I'm thinking of putting the form within a div that literally blocks the page behind it and using css and javascript to show and hide the div as appropriate.

Any ideas and or help?

Thanks,

dog

djr33
11-24-2006, 09:10 PM
If you're talking about live interaction, that's javascript, not php.

If you are ok with submitting the form, then php checking it, which would be MUCH more secure (where javascript can be bipassed), then that's a better option.

Just have a check...

<?php
//top of your page:
if ($_POST['pass'] != "test") {
echo '<form .......>...</form>'
exit();
}
?>
All html goes here. Since the if includes "exit" then this won't be displayed unless the password check verifies.
There are other ways to do this as well... doesn't need to be a password. Could be a checkbox, etc.


To make it more complex, you'd want to do something with cookies.
However, cookies can be faked. As such, you could also include some server side storage (database, I'd suggest) with php, so that you can store the IP address and the "signed in" or not variable, etc. so that the cookie and that must match.
You could also use sessions, which are a fun little php thing that use cookies and other means to send data from page to page and would keep the user logged in, BUT only for that visit... if they close the window, or come back later, etc. it wouldn't keep them logged in.