Ask a Question related to PHP Development, Design and Development.
-
Steve #1
Rejecting blank fields in forms
Hi All,
I hope that someone maybe able to help me with this question. At the moment
I have the following line of code that checks if a field is blank:
if($name == "") {echo "<p><b>PLEASE CLICK 'BACK' ON YOUR BROWSER AND ENTER A
VALID NAME</b>";} else {echo "Name: $name";};
But is there a command that could just detect a null and go straight back to
the form page rather than requesting that the user clicks the back button. I
know this is probably a pretty simple problem for some of the pros, but I'm
a real newbie to PHP! Of course, a few suggestions on a more elegant way to
implement this check would also be very interesting to read!
Thanks if you can help!
Steve
Steve Guest
-
Help with Access fields when they are to remain blank
I have some sections of my database that will be left empty. I am trying to update my database via my web admin pages without any success. What... -
Blank fields in database
Hi, I have a blank field in the database for Address. How do I refer to that? For ex: Set hrRS = Server.CreateObject("ADODB.Recordset") ... -
UNLOAD STATEMENT - Blank Fields Wanted
I thought I've seen this before, but I can't find my reference. What I need is to do the following statement: UNLOAD TO "./ord_reg.unl" SELECT... -
Datasheet Fields Blank
Hi , When using a datasheet view on Subform. Everytime I move to the next record, my fields on the previous record which have the Requery... -
Blank form fields passed to SQL
In your sql statement, check if the value is empty. I don't know what scripting language you are using so I will give an example using coldfusion ... -
Duncan Jones #2
Re: Rejecting blank fields in forms
"Ian.H" <ian@WINDOZEdigiserv.net> wrote in message
news:pan.2004.04.05.13.16.47.859000@bubbleboy.digi serv.net...moment> On Mon, 05 Apr 2004 13:11:39 +0000, Ian.H wrote:
>> > On Mon, 05 Apr 2004 12:26:13 +0000, Steve wrote:
> >> >> Hi All,
> >>
> >> I hope that someone maybe able to help me with this question. At theENTER A> >> I have the following line of code that checks if a field is blank:
> >>
> >> if($name == "") {echo "<p><b>PLEASE CLICK 'BACK' ON YOUR BROWSER ANDback to> >> VALID NAME</b>";} else {echo "Name: $name";};
> >>
> >> But is there a command that could just detect a null and go straightbutton. I> >> the form page rather than requesting that the user clicks the backI'm> >> know this is probably a pretty simple problem for some of the pros, butway to> >> a real newbie to PHP! Of course, a few suggestions on a more elegantmatch> >> >> implement this check would also be very interesting to read!
> >>
> >> Thanks if you can help!
> >>
> >> Steve
> >
> > Hi Steve..
> >
> > Yes, 'isset()' will detect _NULL_ but this isn't really what you want =)
> >
> > There's a similar function... 'empty()' but be aware, this will alsozeros> > '0' (zero) as empty.
> >
> >
> > if (empty($foo)) {
> >
> >
> > The other way is strlen() (assuming it's a string):
> >
> >
> > if (strlen($foo) < 1) {
> >
> >
> > Like many things.. there's more than one way to do it.. much will depend
> > on your preferred coding style.. just watch out for the empty() andmyself).>> > if applicable =)
>
> Should have also mentioned (for the rest of your query).. you can use the
> header() function to perform a redirect back to your form page (see
> <http://php.net/> for more info on this) if this fails, for example:
>
>
> if (strlen($_POST['username']) < 1) {
> header('Location: [url]http://.............com/form.php');[/url]
> exit;
> } else {
> /* Do more processing............. */
> }
>
>
> Personally, I normally send the form back to the originating script and
> use a condition:
>
>
> if (!empty($_POST['submit'])) {
> /* Do processing of form... */
>
> } else {
> /* Display form HTML etc */
> }
>
>
> and for the form action, something like $_SERVER['PHP_SELF'] (although
> this depends on any QUERY_STRING vars I might have in use also forHi Steve,>
>
> Again.. HTH =)
>
>
>
> Regards,
>
> Ian
>
> --
> Ian.H
> digiServ Network
> London, UK
> [url]http://digiserv.net/[/url]
>
I would say that Ian's suggestions are the most sensible PHP-way to redirect
the user back to the original form to correct their mistakes. However, the
original values they entered will not be in the textboxes (unlike if they
pressed "back" in their browser).
PHP is not an ideal way to check forms for errors, as it runs on the server
side and thus all the information is already sent. If I were you, I would
use javascript to check the fields are full before sending. This way, it
can provide instant feedback to the user about whether they have made a
mistake. Naturally, not all people have javascript enabled, so you would
also want to implement a PHP-check (as Ian suggests) to cover all grounds.
For an explanation on how to validate forms using javascript, see the link
below:
[url]http://www.yourhtmlsource.com/javascript/formvalidation.html[/url]
Alternatively, if the form does not contain sensitive information, perhaps
you could use a PHP page to regenerate the form with the values previously
entered. E.g. <input value="theoldvalue">.
Regards,
Duncan Jones
[url]http://www.renquish.com[/url]
Duncan Jones Guest
-
Steve #3
Re: Rejecting blank fields in forms
Thanks for the help there, guys - it's got me up and running!
Steve
"Ian.H" <ian@WINDOZEdigiserv.net> wrote in message
news:pan.2004.04.05.13.51.38.625000@bubbleboy.digi serv.net...perhaps> On Mon, 05 Apr 2004 14:35:40 +0100, Duncan Jones wrote:
>
>
> [ snip ]
>
>> > Alternatively, if the form does not contain sensitive information,previously> > you could use a PHP page to regenerate the form with the values>> > entered. E.g. <input value="theoldvalue">.
>
> This works for sure and normally what'll do (I didn't for this brief
> example). Especially if the form is posting to iself this becomes a
> trivial task to do.. just validate, format and print back as you say.
>
> The other alternative I've used is SESSIONs. When the form posts, store
> the info (_NOT!_ passwords etc) in a SESSION var which is then accessihble
> to do the same echo as you explain above.
>
> Your suggestion of both Javascript and PHP validation is also a good one
> IMO =)
>
>
>
> Regards,
>
> Ian
>
> --
> Ian.H
> digiServ Network
> London, UK
> [url]http://digiserv.net/[/url]
>
Steve Guest
-
Manuel Lemos #4
Re: Rejecting blank fields in forms
Hello,
On 04/05/2004 09:26 AM, Steve wrote:You may want to take a look at this forms generation and validation> I hope that someone maybe able to help me with this question. At the moment
> I have the following line of code that checks if a field is blank:
>
> if($name == "") {echo "<p><b>PLEASE CLICK 'BACK' ON YOUR BROWSER AND ENTER A
> VALID NAME</b>";} else {echo "Name: $name";};
>
> But is there a command that could just detect a null and go straight back to
> the form page rather than requesting that the user clicks the back button. I
> know this is probably a pretty simple problem for some of the pros, but I'm
> a real newbie to PHP! Of course, a few suggestions on a more elegant way to
> implement this check would also be very interesting to read!
class that was meant exactly for what you want:
[url]http://www.phpclasses.org/formsgeneration[/url]
--
Regards,
Manuel Lemos
PHP Classes - Free ready to use OOP components written in PHP
[url]http://www.phpclasses.org/[/url]
PHP Reviews - Reviews of PHP books and other products
[url]http://www.phpclasses.org/reviews/[/url]
Metastorage - Data object relational mapping layer generator
[url]http://www.meta-language.net/metastorage.html[/url]
Manuel Lemos Guest



Reply With Quote

