[PHP] Re: recursion?????

2003-02-15 Thread Fred Merritt
Alex,
		as a general rule of thumb, try to do as much checking as you can with 
JavaScript.  For those checks such as "is the field a valid date", "is 
the field numeric" and so on, it is much faster to check on the client, 
than to send the data back to the server and check it there.  Probably 
the best way to do this is with an "onSubmit" clause on the . 
Something like:



Some things you cannot check on the client, for example does the value 
of the field already exist in a data store on the server.  There are 
many ways in which you could check these fields.  On of the easiest to 
understand ways would be to name your submit field something like 
"Register", and use code something like the following in register.php:

switch ($_POST['submit']) {
	case "a";
		processA();
	break;
	case "b";
		processB();
	break;
	case "Register";
		checkFormAndRedisplay();
	break;
	default;
		processDefault();
	break;
}

In the procedure checkFormAndRedisplay(), you can write code to check 
your fields, and the relationships between them, and then redisplay the 
form with appropriate error messages, and highlighting, to guide the end 
user to correct his errors.

Hope this helps. . . Fred

Alex Davis wrote:

Ok ... here is the sitituation... I am creating a registration form.
What I have so far works ... the user registers using this form and the
form calls another page that will check the validity of the data
(checking for username availability, etc...). If there is an error,
display the error and have the user GO BACK AND TRY AGAIN <- This is
the problem I want to fix.

What I want to do is have the registration form, on submit, check the
data validity right then, if there is an error, redisplay the form with
an * next to the field that is incorrect. This way the user does not
have to go back and try again, it will be there in front of them.

Basically, have the form action call itself  hince the recursion.

Any suggestion/examples?

Thanks,

-Alex





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




[PHP] Re: Recursion?????

2003-02-15 Thread Fred Merritt
Alex, and Michael,
			here is a code fragment which I have cut and simplified from one of 
my working scripts, that does some simple javascript checking of a form. 
 It should give you an idea of how to do it.  There is a lot of 
documentation, and examples of javascript on the web.  Try a google 
search.  At this level it is relatively easy(well at least it is after 
you have done it once).  When you get into more complicated javascripts, 
you have to take into account that because of different document object 
models, some things are implemented differently in different browsers.

. . .
?>



. . . The key thing to notice here, is that the submit will only happen if the onSubmit returns true. Hope this helps. . . Fred Michael Eacott wrote: Alex Like you I have php scripts that validate the contents of registration and other forms. I'm new to php and do not have a clue about client side (java) scripting. Yes and the GO BACK AND TRY AGAIN process is what my php scripts do. All very messy. I'll have to learn javascript but currently I have a deadline to meet with the php implementation.Be interested to see sometime in the future the javascripts you write to validate you forms. Regards Mike Eacott rentAweek Ltd http://www.rentaweek.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP] Re: recursion?????

2003-02-15 Thread Fred Merritt
David,
	of course.  You always should check in the server, even if javascript 
is working.  You have to protect your data integrity.  Sorry I did not 
make this clear.

The benefit of checking in javascript(which I suspect is enabled in most 
browsers these days), is that the client gets an instant response for 
the out of line situation.

Best regards. . . Fred


David Freeman wrote:
 > 		as a general rule of thumb, try to do as much
 > checking as you can with
 > JavaScript.  For those checks such as "is the field a valid
 > date", "is
 > the field numeric" and so on, it is much faster to check on
 > the client,
 > than to send the data back to the server and check it there.

Except, of course, that you need to check it AGAIN in your php script in
case the browser has javascript disabled - because if it's disabled
you'll end up with unchecked form data.

CYA, Dave






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




[PHP] Re: date calculation

2003-02-16 Thread Fred Merritt
Qt,
	The easiest way is to convert your dates into a serial day number(i.e. 
the number of days that have elapsed between your date, and some 
arbitrary date in the dim and distant past - I think PHP uses 25th 
November, -4714).  There are some calendar functions in php that will do 
this for you.  Once you have your dates as a numeric offset, you can 
subtract them to get a the number of days between the dates, or you can 
add or subtract a number of days to get a new offset.  Once you have the 
new offset, there are reverse calendar functions in php, to convert your 
new offset back to a calendar date.

Check out the functions GregorianToJD(), and JDToGregorian(), in the 
Calendar functions of the PHP manual.  If you do not have access to the 
calendar functions in your version of php, there are also a couple of 
examples how to do one of the conversions written in PHP, in the user 
contributed notes of the manual.  There are also many published articles 
describing algorithms on how to do this.  I can remember implementing 
these functions in 1977(Not in PHP of course), from an article published 
in the journal of the ACM, in 1963.

Hope this helps. . . Fred

Qt wrote:
Dear Sirs,

How can I add or subtract two date easily. Is therea any lib or function
about this. I can not find any easy way in the manual

Best Regards





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