PDA

View Full Version : php script


RevKev
05-17-2001, 04:48 AM
Here's what I want to do:

I have a form for people to send prayer requests being handled by prayer_response.php. I want to require certain fields to be filled out. I would like to use an "if" clause that would basically do:

if ($prayer == null || $name == null || $email == null)
{
echo "<p><strong>You must complete all fields.<br/>Please return to the last page and try again.</strong></p>";
require("footer.inc");
exit;
}

I'm guessing the part inside the {} is just fine. It's the if clause that I'm not sure about. Obviously the word "null" is just to let you know what I'm trying to do. There must be some neat way of doing this, though.

If you know, please let me know. :)

Thanks!

RevKev
05-17-2001, 05:13 AM
Hmm... If I talk to myself enough, I start to pull things out of my ..... anyway.....

Here's what I'm trying:

if (isempty($prayer) || isempty($name) || isempty($email))

We'll see if it works. :)

sylow
05-17-2001, 05:16 AM
Do it in javascript and dont let them submit form if required fields are empty. It will make people life's easier by forcing them to fill fields in the same page instead of going somewhere coming back

RevKev
05-17-2001, 05:22 AM
Ooh... That would mean having to learn javascript... :)

Okay, I've been talking to myself again and have two more options. Anyone using them have a pref?

1) if (!isset($name) ||.....

2) if ($name == "" ||.....

I'm guessing that both clauses do pretty much the same thing. Which to use, then?

eric418
05-17-2001, 05:57 AM
there is no different for them. so just use either one of them.

for me, i check field in a similar way, but u can set it to display back to the form with a error message. So user won't have to go back to the page.

here is my page with login thing, try submit it with nothing entered or just left a field empty. might have u some idea.

http://leungeric.com/eric/login.php

RevKev
05-17-2001, 06:00 AM
For some reason, using !isset() didn't work, but $var == "" did. I thought they were the same, too. Oh, well... as long as it works! :)

I like what you do with your login. Looks like a good next step for me when I get bored.

Thanks for the help!

sylow
05-17-2001, 10:04 AM
isset($variable) Returns true if $variable exists; false otherwise.
empty($variable) Determine whether a variable is set
sorry but there is no isempty function in php is it the function you write yourself?