Form validation/compulsary fields help needed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
awhittle
Forum Newbie
Posts: 2
Joined: Mon Nov 13, 2006 4:24 am

Form validation/compulsary fields help needed

Post by awhittle »

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 all,

I am wondering if anyone can point me in the right direction as to how i make some of my fields on my form compulsay.

[syntax="html"]<form action="/php/testfcontactform.php" method="post" name="contact-form" id="contact-form">
            <fieldset>
            <p>
              <legend><span class="Products"> Your contact details</span></legend>
            </p>
            <div><span class="style7">
              <label for="fName"><span class="style14">Name</span></label>
              </span>
              <input name="fName" type="text" class="style8" id="fName" size="35"/>
            </div>
            <div><span class="style7">
              <label for="fEmail"><span class="style14">Email * </span></label>
              </span>
              <input name="fEmail" type="text" class="style8" id="fEmail" size="35"/>
            </div>
            <div><span class="style7"></span>
              <label for="fSubject"><span class="style14">Subject</span></label>
              <input name="fSubject" type="text" class="style8" id="fSubject" size="35"/>
            </div>
              <div><span class="style7"></span>
              <label for="fMessage"><span class="style14">Your Message</span></label>
              <textarea name="fMessage"id="fMessage" class="style8" rows="6" cols="40"></textarea>
            </div>
            </fieldset>
            <div align="center">
              <input type="submit" name="submit" value="Send" />
              <input type="hidden" name="do" value="send" />
              <input type="reset" name="reset" value="Reset" />
            </div>
          </form>


PHP bit[/syntax]

Code: Select all

<?PHP
$do = ($_POST['do']);
if($do == "send")
{
	$recipient = "ashle@whittle.tc";
	$fSubject = ($_POST['fSubject']);				// Subject of E-mail //
	$fName = ($_POST['fName']);					// Senders Name//
	$fEmail = ($_POST['fEmail']);					// Senders E-mail address //
	$fMessage = ($_POST['fMessage']);				// Content of Message //
	$formsend = mail("$recipient", "$fSubject", "$fMessage", "From: $fEmail ($fName)\r\nReply-to:$fEmail");

}

?>
any help / advice much appriciated

thanks


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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Just check if the $_POST element for it is empty() or not.

FYI, you should place

Code: Select all

 ... [/php ] tags around your code when posting on the forums ;)
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

Or you can use

Code: Select all

if($_POST['name']==''){$ermsg='Empty field' .$_POST['name'];}
awhittle
Forum Newbie
Posts: 2
Joined: Mon Nov 13, 2006 4:24 am

Post by awhittle »

Thanks you for quick responce,

just a quick question, how does entering this code work when i have a HTML page ref a php script. when you press submit button on main page, should this script run this file and process commands then return error message if something is missing or would i be best to include the PHP code into the main page (asSELF) any suggestions.

basically what i am trying to achive is an online e-mail form but with certain field compulsary?

Also is there a way of adding more fileds into e-mail

i currently have

Code: Select all

$formsend = mail("$recipient", "$fSubject", "$fMessage", "From: $fEmail ($fName)\r\nReply-to:$fEmail");
but i would like to also add phone number?

how would this link in?

Thanks
Post Reply