On Friday 24 June 2005 04:09, Joseph Harris wrote:
> I am just settling in my mind conflicting ways of dealing with forms.
>
> In one the user box is identified by name="whatever" and that is
> dealt with by the action file.
>
> The other is something like this: value="<?=$_POST['first_name'];?>"
> also dealt with by the action file.
>
> Am I right in thinking the second would be used where there is a
> range of options to select from.   I have an example which, as there
> is no list, produces a notice of an unidentified variable and also
> shows the php code in the textbox.
>
> Is there a reason for using the second version where the form is
> filled with new information?

The second version simply writes the value of $_POST['first_name'] (if 
there is one) in place of the <?....?> bit.

This is useful if the form has been submitted but something was wrong 
with the input, you can re-display the form with the values that were 
submitted filled in.

However, if the form hasn't yet been submitted to itself, that will not 
work, you'd need to do something like:

<input .... value="<?php echo (isset($_POST['first_name']))?
        $_POST['first_name'] : ''; ?>">
(that could all be on one line)

That'd stop the problems with undefined variables.

If your form is submitting to a seperate "action" file then that won't 
help you anyway.

It sounds as though you're trying to figure out how to get at the 
contents of form fields submitted to the PHP script, am I right?

In that case, given a field:
<input type="text" name="first_name" value="" />
in the form, when the form is POSTed to the PHP script, the value the 
user entered in the first_name field can be found in 
$_POST['first_name'].

I'm not sure what you mean by "lists" - if you mean a simple select 
list, it works the same.

If it's a set of checkboxes, the easy way is to do:

<input type="checkbox" name="Food[]" value="Chicken" />
<input type="checkbox" name="Food[]" value="Pizza" />

Because of the square brackets in the name 'Food[]', the contents of 
$_POST['Food'] when submitted will be an array of the items that were 
checked.

The same principle applies for a multiple <select> field.

Hope this helps a little?

Cheers

Dave P






____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] or
use the web interface http://e-newsletters.internet.com/discussionlists.html/
       Send Your Posts To: [email protected]
To change subscription settings, add a password or view the web interface:
http://intm-dl.sparklist.com/read/?forum=wdvltalk

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]
To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.

Reply via email to