Page 1 of 1

Checking for blsnk fields

Posted: Wed Jun 27, 2007 9:39 pm
by malloy
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi everyone,

This should be so simple but I just can't crack it.

I have an online form and I want to make sure there are no blank fields being submitted. I'm not sure on how to do this. The simpler the solution the better.

Here is a snippet of my online application.php code

[syntax="html"]<body>

<form action="email application.php" method="post" name="online application" class="style1" id="online application">
<fieldset>
<label for="name">Name of Child: </label>
		<input name="name" type="text" id="name" title="name" value="">
<br>
	<label for="dob">Birth / Expected Arrival Date: </label>
		<input type="text" id="dob" name="dob" title="dob" >

Would i put the verification form into this online application.php or into my email application.php also im not sure.

Any assistance would be greatly appreciated or even a link to a good reference.

Kind regards,

David


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jun 27, 2007 10:42 pm
by mabufo
The form will pass email application.php two variables:

Code: Select all

$_POST['name']
and
$_POST['dob']
You simply need to use a conditional to check that they have been set with the data inputted by the user. Like so:

Code: Select all

if (isset($_POST['name'], $_POST['dob'])) {
    echo "This var is set so I will print.";
}
else{
     include("form.php");
     echo 'Please input data.';
}
I suppose you could set the above code up inside of a loop that iterates through the _POST array as well - that would be a little more work however.

Posted: Thu Jun 28, 2007 1:26 am
by malloy
Hi again,

Ive been playing around with the email application.php file but still no luck

Here are the last lines of code that im stuck on. I constantly receive the 'Please input data' message even when the name field is populated with text.

Code: Select all

if (empty($name)) 
{
    echo 'Please input data.';
} 
else {
mail($sendTo, $subject, $headers);
}
?>
Any suggestions or alternative methods? I tried the method above too with no avail.

Cheers,
David

Posted: Thu Jun 28, 2007 2:20 am
by mabufo

Code: Select all

if (empty($_POST['name'])){
do something
}
You need to specify that the variable resides in the _POST array, from your form. the isset() function would work fine here as well; check my example. You receive the message because '$name' doesn't exist outside of the post array.

If you want to simplify things for yourself, set your post variables to regular variables.. like so:

Code: Select all

$name = $_POST['name'];