x-nitro Posted October 31, 2010 Share Posted October 31, 2010 Dear friends, Can anybody help me just to add php code to make field as a required? <? if(!isset($_POST['answer'])) { ?> <form action="index.php" method="post"> <p></p>Please fill out your personal details and answer the questions by clicking on your answer.</p> <p>Good luck!</p> <table cellspacing="0" cellpadding="3" border="0"> <tr> <td>Your Name:*</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>Tel #:*</td> <td><input type="text" name="tel" /></td> </tr> <tr> <td>Email:*</td> <td><input type="text" name="email" /></td> </tr> <tr> <td colspan="2"> Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2010 Share Posted October 31, 2010 Can do something like this (substitute your variables of course) if (isset($_POST['uname']) || isset($_POST['pword'])) { //submitted, check values if (empty($_POST['uname'])) { die ("Error: Enter a username"); } if (empty($_POST['pword'])) { die ("Error: Enter a password"); } } Quote Link to comment Share on other sites More sharing options...
x-nitro Posted October 31, 2010 Author Share Posted October 31, 2010 Where to put it exactly? Guys I dont know php, programmer who has write this php traveled. So I need to adjust this text-fields to be required. Please explain simply as much as possible Quote Link to comment Share on other sites More sharing options...
revraz Posted October 31, 2010 Share Posted October 31, 2010 My advice then is to learn PHP or hire someone to do it for you. Quote Link to comment Share on other sites More sharing options...
x-nitro Posted November 1, 2010 Author Share Posted November 1, 2010 Can you do that? and how much it will cost? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted November 1, 2010 Share Posted November 1, 2010 <?php if ( isset($_POST['submit']) ) { $name = isset($_POST['name']) ? $_POST['name'] : ''; $tel = isset($_POST['tel']) ? $_POST['tel'] : ''; $email = isset($_POST['email']) ? $_POST['email'] : ''; $errors = array(); if ( empty($name) ) { $errors[] = 'You did not enter your name.'; } if ( empty($_POST['tel']) ) { $errors[] = 'You did not enter your telephone number.'; } if ( empty($_POST['email']) ) { $errors[] = 'You did not enter your email address.'; } if ( filter_var($email, FILTER_VALIDATE_EMAIL) === false ) { $errors[] = 'You must enter a valid email address.'; } if ( count($errors) == 0 ) { //do something with collected data i.e. insert into a database // echo 'Done'; } else { $error = <<<ERROR <table style="width: 200px; margin: 0 auto 0 auto; color: darkred; border: 1px solid #000;> <tr> <th style="font-weight: bold;">Errors:</th> </tr> <tr><td> implode("</td></tr>\r\n\t\t<tr><td>", $errors) </td></tr> </table> ERROR; echo $error; } } ?> <form action="index.php" method="post"> <p></p>Please fill out your personal details and answer the questions by clicking on your answer.</p> <p>Good luck!</p> <table cellspacing="0" cellpadding="3" border="0"> <tr> <td>Your Name:*</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>Tel #:*</td> <td><input type="text" name="tel" /></td> </tr> <tr> <td>Email:*</td> <td><input type="text" name="email" /></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="Submit" /></td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
x-nitro Posted November 1, 2010 Author Share Posted November 1, 2010 Thanks Andy.. Really appreciated Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.