Re: PHP inside Javascript

From: Date: Tue, 12 Sep 2000 05:47:12 +0000
Subject: Re: PHP inside Javascript
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-16279@lists.php.net to get a copy of this message
At 11:26 AM 9/5/00 -0700, you wrote: >Ron Newman writes: >> problem I've had in the past in using PHP to validate is the mess of >> redisplaying the page and indicating the missing fields to the user. >> Javascript allows the quick popup of a dialog without waiting for another >> page to download or using the backbutton. >One way to do it (not the only and not perhaps the best :): > >You can just keep an array of the expected inputs (perhaps including >error messages, which also makes localization easier), then loop >through it on submit and check against the incoming data. If an item >is missing or otherwise invalid, add its message ('Malformed email >address' or 'Please enter a username' or whatever) to an error string >which gets output back to the user. Use the submitted values to >re-fill the form inputs, and present the page back to the user. Put >this code into a library function, and all you need to do is us a >switch() or some function calling to choose which path you want to go: >display the 'you need to fill in this form better' output, or the 'you >succeeded' output. > >Something vaguely like: > > if (validate_input($input_template, $HTTP_POST_VARS)) { > do_something_wonderful(); > } else { > display_errors(); > display_form(); > } > >...or is this not what you meant? > >-- >+----------------------------------------------------------------+ >|Torben Wilson <torben@php.net> Netmill iTech| >|http://www.coastnet.com/~torben >http://www.netmill.fi| >|Ph: 1 250 383-9735 torben@netmill.fi| >+----------------------------------------------------------------+ It's been a while, I've been off on other things, and now back to this. Is this what I meant? Sortof. But: What's the best way to "re-fill the form inputs" without using javascript, before presenting the form page again? - print a META tag with refresh - header(Location:...) I'm not aware that either of these know anything about forms. I use META refresh in another place to propagate form data, but that's in conjunction with an HTML tab: <BODY onLoad="javasubmitfunction()"> in which case we're back to Javascript, the very thing I'm trying to avoid. Hmmm. ************************************************* Ron Newman Troubadour Technology http://www.imt.net/~ronman/ *************************************************

« previous php.general (#16279) next »