faqts : Computers : Programming : Languages : PHP : Common Problems : Variables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 10 people (100%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

FORM: If field1 is empty,then I want the information from field2 of a form to be filled into field1

Dec 24th, 2005 04:23
Dan Stockton, Dan Stockton, Ricarda,


this would be done in javascript...
 .. not real proficient with the syntax but it would be something like:
var field1value=document.forms.field1[value];
var field2value=document.forms.field2[value];
if(field1value==''){
field1value=field2value;}
no, wait.. that would only hafta be javascript if it's before you 
submit the form. After form submission, PHP could do:
if(!defined($field1)){$field1==$field2;}
  or
if($field1==''){$field1==$field2;}
__
actually, the second argument for each of the last two lines should only have one '=':
{$field1=$field2;}"
because, in php, ('==' = 'is equal to') while {'=' = 'gets set to'}
you would want the value of '$field1' to 'get set to' the value of '$field2' (one equal sign) 
the two examples above, corrected, would be:
if(!defined($field1)){$field1=$field2;}
"if $field1 is not defined, $field1 'gets set to' $field2"
if($field1==''){$field1=$field2;}
"if $field1 'is equal to' [nothing], $field1 'gets set to' $field2"