On Tuesday 05 March 2002 19:20, you wrote:
> 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
>

Hi Erik,

And thanks again!
I like the 'function print_name_form()' -- I gather you could do this for all 
the NOT NULL variables that a form requires. Further, would you just change 
the "print_name" to 'print_whatever-other-variable' that I would want to 
check? Is there another way to consolidate the code at this point? Or would I 
just duplicate the code for each not-null variable?

[Btw, I sometimes long for the old Paradox PAL code that seemed so difficult 
at the time I learnt it -- PHP is very similar, but the syntax seems so much 
more compact.]

While we're on the topic of fields ('input type=text") is there anyway to 
include a non-printing space in the data entry, say for 'Name", that would 
not be passed to the database? Thus, on the screen it would appear:
        
        Name: [non-printing space]Andre   but in the database entry:   Name:Andre

This isn't a pressing question, and probably is a formatting question, but I 
wonder if it's possible?

Tia,
Andre
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> [EMAIL PROTECTED]

-- 
Please pray the Holy Rosary to end the holocaust of abortion.
Remember in your prayers the suffering souls in Purgatory.

May God bless you abundantly in His love!

For a free Cenacle Scriptural Rosary Booklet -- http://www.webhart.net/csrb/

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

Reply via email to