I was wanting to make a program that had an input box, and you have to type a paragraph exactly and you can't use backspace or delete. Any ideas on how I would set this up in php?
You'd probably have to use JavaScript to somehow prevent you from using backspace or delete. I think both JS and PHP have methods for comparing the final paragraph to what has to be typed.
_player1537 wrote:
I was wanting to make a program that had an input box, and you have to type a paragraph exactly and you can't use backspace or delete. Any ideas on how I would set this up in php?
As Keith said, you'd have to use Javascript to catch keys like delete and backspace, and return false on those keys to prevent them from working. On the comparison side, strcmp(str1,str2) would work for case-sensitive comparison, or strcasecmp(str1,str2) for case-insensitive comparison.
This isn't too hard to implement. As a word has completed, it would show up on a DIV, where it can't be erased. At the same time, the script uses AJAX to toss the word onto the server. Afterwards, it shows it on the DIV, and the person keeps on typing.

Are you in need of ideas or code? Smile
alberthrocks wrote:
This isn't too hard to implement. As a word has completed, it would show up on a DIV, where it can't be erased. At the same time, the script uses AJAX to toss the word onto the server. Afterwards, it shows it on the DIV, and the person keeps on typing.

Are you in need of ideas or code? Smile


Yes, very beginner stuff (but nothing like HelloWorld)[/b]
_player1537 wrote:
alberthrocks wrote:
This isn't too hard to implement. As a word has completed, it would show up on a DIV, where it can't be erased. At the same time, the script uses AJAX to toss the word onto the server. Afterwards, it shows it on the DIV, and the person keeps on typing.

Are you in need of ideas or code? Smile


Yes, very beginner stuff (but nothing like HelloWorld)
And you want it to be stuff that's not interactive, correct?
I think interactive. I was thinking something similar to a chat program... But I'm not sure if that would be extremely hard to make
a chat program would require AJAX. SAX is PHP-AJAX, for example.
_player1537 wrote:
I think interactive. I was thinking something similar to a chat program... But I'm not sure if that would be extremely hard to make
If you want to omit the Javascript, it's trivial to make a chat program with a listing of what's been said, then an input box to say something. You can just make the user refresh the page to see if there's anything new. That's more of a guestbook / wall / bulletin board-type of project.

@SubaruZX: cf. my post. Smile
Ok, I'll try that I guess. How would I set it up at first? Like maybe psuedocode
your HTML page has an input box as a form. You submit the form to the PHP, PHP does this:


PHP gets the text from a $_GET or $_POST variable. I suggest $_POST as it's more secure and doesn't have limitations.

PHP opens a text file
the text is added to the bottom of the text file
the file contents get echoed onto the screen


something like that I guess
_player1537 wrote:
Ok, I'll try that I guess. How would I set it up at first? Like maybe psuedocode
On the server side, you'd need something to store the chat text. A database is jumping way ahead, so use a file, where each line is one line that's been said. You can then use PHP filesystem functions like fread(), filesize(), fopen(), fwrite(), flock(), and fclose() to manipulate. To read, you just fopen, fread, fclose. To write, you fopen, flock, fwrite, flock (to unlock) and fclose. Pro-tip: php.net/[nameoffunction] for quick reference.

The serverside script should by default spit out the chat text, then a form with an input box for a username, an input box for a line of text, and a submit button (do what you want for the username, maybe omit it? Your call). On submit, pass a $_POST variable to the PHP script, which will still spit out the chat text and the form, but only after it adds the new text. That's the simplest implementation.
HTML side, you need to set up a var that is linked to the AJAX object. w3schools has a beautiful example to use. Wink

Then, you need to place "hooks" (events, in JS) onto the text box. on_____ is usually the thing you need. Hook it to a JS function.

The JS function then takes the latest word, tells the AJAX object to send it, and awaits a success response.

In the meantime, the PHP script uses the $_GET or $_POST var to retrieve data, and return a number for success.
Once done, the div is appended.

Once the whole thing is done, the script sends something like done=1 to the PHP script, and the thing closes up.

For blocking backspaces, on specific events, if it uses a specific key, you can reject it by returning false.

Hehe, if you really want to, you can ditch the text box and make the div "typeable" - emulate a cursor, and let the person type while implementing the same AJAX/PHP communication. Try that! Wink
alberthrocks wrote:
HTML side, you need to set up a var that is linked to the AJAX object. w3schools has a beautiful example to use. Wink

Then, you need to place "hooks" (events, in JS) onto the text box. on_____ is usually the thing you need. Hook it to a JS function.

The JS function then takes the latest word, tells the AJAX object to send it, and awaits a success response.

In the meantime, the PHP script uses the $_GET or $_POST var to retrieve data, and return a number for success.
Once done, the div is appended.

Once the whole thing is done, the script sends something like done=1 to the PHP script, and the thing closes up.

For blocking backspaces, on specific events, if it uses a specific key, you can reject it by returning false.

Hehe, if you really want to, you can ditch the text box and make the div "typeable" - emulate a cursor, and let the person type while implementing the same AJAX/PHP communication. Try that! Wink
Err, true, but if you careful read some of the posts, _player wants to start with something simple and non-Javascripted. Then he can move on to the Javascript-assisted, interactive, AJAXified stuff. He needs to learn the foundations first! Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement