Press any key to continue - how?

A

Anonymous

Guest
I've searched for this but it's like looking up a word in a dictionary without knowing the first letter! What am I looking for?

OK, I reach a point in my PHP script where I want the computer user to make a choice. Press B to go back (exit;) or press C to continue (so the script continues).

How the heck do I achieve this? I've no idea how to look for keyboard input.

(Bring back BASIC; all is forgiven. Then I could use GET).

Martin
 
you want to achieve this in web application?
-your application type web|console,command line?
 
Code:
<?php
$words = "";
$Message = "satalite satallite sattalite satelite sattelite LMB reciever";
$array = array('satalite','satallite','sattalite','satelite','sattelite','lmb','reciever');
reset($array);
do {
$key = key($array);
$pos = strpos(strtolower($Message), $array[$key]);
if ($pos == true) {
$words .= " " . $array[$key];
}
} while (next($array));
if ($words == true) {
echo( "Message contains the following incorrect technical words: " . $words );exit;
}
?>
Press B to go back and correct it.
Press C to continue.
GET key input
if key input =
etc.

This is running in a web browser.
 
In a web application, it's very much preferable to use user interface elements that users are familiar with, e.g. links and buttons. Forcing users to use keypresses for navigation is a step backward in user interface design, and will only create confusion.
 
Well, it's certainly caused confusion in my 52 year old brain! As you can no doubt tell, I was brought up on Fortan IV and BASIC so all this GUI stuff is new to me.

It may be obvious to you how to get a user input but it's a complete mystery to me. I can generate an HTML "form" if that would help. But I don't see how that fits in with PHP to get a go/no go input.

Or do I now have to learn javascript?

:cry:

Martin
 
Maybe I'd understand better if you gave me the bigger picture. What, exactly, are you trying to accomplish?
 
People write to me for free technical advice. They fill in a "form", click "Send" and it hits my PHP script. Frequently they get the technical terms wrong so the script looks for common misspellings. If it finds any it lists them and asks the person if he wants to send the message regardless (which annoys the f**k out of me) or go back and copy the words correctly. This helps me to weed out the people deserving a free reply from the idiots, the lazy and the unfortunately dyslexic! If the person is incapable of copying words then I know I'm wasting my time in replying because he won't understand my answer anyway.

The section of script (above) is the bit that does the checking. In practice it looks for a lot more words. I've included only a sample.

My problem is that, although I'm familiar with basic HTML and I'm gradually getting to grips with PHP, I have an obvious "blind spot" when it comes to marrying the two together!

I hope I'm not coming across as either lazy or an idiot. :wink:
I just don't know where to begin. Maybe it's just senility setting in.

Oh, it might help to look at the form:
http://www.satcure.com/techmail.htm

Martin
 
Hi,
I may be half of your age... but... may be I may help you...

why don't you check some words for common spelling mistakes in php,
IF you do find them ,list them to the user in the html format...
ANd give him options whether to rectify them or send them as typed...

The two links should exectute the same php script where you can check for a variable say $correct
IF $correct = "y" THEN.... replace the words.. or whatever
ELSEIF $correct = "n" THEN.. do otherwise..
 
That's certainly an option but it doesn't answer my fundamental question "how to I detect user input" and it doesn't really fulfil my intention of getting rid of the lazy sods who want to email me! It makes it too easy. :wink:

Martin
 
So I've got you all stumped on this one!

Well, I'm glad I'm not the only one who can't figure it out. :wink:

Martin
 
Ok, I understand that if I simply want the person to go to another web page I give him a link like:

echo('<P><FONT SIZE="+1" FACE="Verdana">Please click </FONT><A HREF="http://www.satcure.co.uk/useful/tech_help.htm"><FONT SIZE="+1" FACE="Verdana">here</FONT></A><FONT SIZE="+1" FACE="Verdana">
for more information.</FONT></P>');

What I don't get is how to simply let the exited PHP program carry on? Presumably I have to use something other than "exit;"

Or how to construct the HTML to let him go back to the previous page (the form)?

Martin
 
Busy week, I haven't had much time to check in.

I see what you're after now. What you're looking for is a sort of "preview" or "confirm" page where the user can change values he entered previously. Well, all you need to do is make sure the values get stored (hidden form fields if you're using forms, or session variables, or a database will all work), and then when they go to the "change your previous entries" page, just display a form just like the one they used previously, but fill in his previous values for him.

This sort of thing is seen most often in what's called "form validation" (e.g. when a user enters an invalid ZIP code and the server sends them to a form with the erroneous fields highlighted for them to change), and there's all manner of tutorials on it out there.

Concerning letting the script "carry on", you can't. This is one of the limitations of the HTTP environment, and the bane of every web programmer. Once the page has finished loading, the browser and the server no longer communicate, and the script is terminated. That's why we have things like sessions in order to "maintain state" from page to page.
 
Actually you are overcomplicating what I thought I wanted to achieve, although the answer may be the same in the end!

The choice was either for the user to go back to the form page (which he can do by pressing his "back" button once the program has exited) or to let the program send the email without alteration. That was my intention anyway....

That's why I was looking for a way to "pause" the PHP program to look for a Y/N key input. But from what you say, the program can't display until it has ended. Forgive my newbie ignorance on this. I'm still living in the land of BASIC! But I see now that the script gets run on the server, then displays whatever, then exits and at that point I'm back into HTML. There's no way I can get it to pause in the middle!

OK, I'd better learn how to create HTML forms with PHP.

Thanks for your help. :?

Martin
 
Back
Top