On Tuesday, March 5, 2002, at 07:01  PM, Andre Dubuc wrote:
>
> Now that makes sense. I'm getting a better idea of how it works 
> together. I
> figured there must be a way to control the "Submit" button's behaviour, 
> but I
> didn't know where to look.

Yep, the submit input tells the form "go do your thing", but the form 
already knew where to go (because you specify where to go in the 
'action' attribute).  The form also knows how to go -- whether it should 
be POST or GET.  Without realizing it, you'll be learning more about the 
HTTP protocol itself as you start writing scripts that take advantage of 
its features.

> Where would you insert:
>
>       if (!isset($name)) die ("You need to fill in your name.  Use the 
> browser's             
>       back button and input this information.");
>
> I tried in the php database storage code (didn't work). Tried it after 
> the
> appropriate 'Name' code in the form's html document. Didn't work. I know
> that it should work somewhere . . . .
>
> Somehow, I don't think the "Submit" function is working as it should
> (especially if a carriage return or "Enter" can override everything). Is
> there some code that will defeat this undesirable activity?

Firstly, your browser is what determines how the form is sent -- but 
usually, it's normal for the Enter key to act as the "Submit" button (a 
nice keyboard shortcut that I take advantage myself).  It should not act 
in this fashion if you are typing into a textarea tag, because you might 
want to enter newlines/cr's in the textarea, but for most other form 
fields it's normal.  If you want to jump from one field to the next with 
a key press, use tab.

Secondly, you're wondering where to check for the presence of the data?  
How about this:

<?php
function print_name_form()
{
        print "<p><input type=\"text\" name=\"name\" /></p>";
}

if (!$_POST['name']) {
        print "<p>You need to fill in your name.</p>";
        print_name_form();
} else {
        print "<p>Thank you!</p>";
}
?>

Why did I define a function in the beginning?  Well, this way, if the 
user didn't enter a name, they don't have to hit "back" in their 
browser.  The form just appears again.  This is much more useful if you 
have this same function accessible from each page/script you are 
writing, so that you don't have to waste your time.  Later, when you 
learn how to check for errors in your user's input (such as if the user 
entered a bunch of numbers instead of a name), this will come in handy 
so that you can save the user's legitimate values but ask them to 
re-enter their invalid values.  That gets kind of technical, but it's 
one of the sweet things about functions, that they are reuseable.

Erik


----

Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to