Zer0Cam Posted September 17, 2007 Share Posted September 17, 2007 Ok So I want to make 2 of the selected fields REQUIRED Teacher Name: Room Number: This is the code I have <?php // page_ticket_submit.php: Page to submit a new ticket if (!defined('IN_SUPPORT') || eregi("page_ticket_submit.php",$_SERVER['PHP_SELF'])) die("You can't run this directly!"); session_start(); // If the user isn't logged in if (!isset($_SESSION['support_in']) || $_SESSION['support_in'] !== true) { header("Location: http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=login&return=ticket_submit"); } // If they've submitted one if (isset($_POST['submit2'])) { // If no subject entered if (!isset($_POST['subject']) || $_POST['subject'] == "") { writeError("ERROR: You must enter a subject. Please click the 'Back' button in your browser to fix this."); die(); // No message? That's not helpful at all } elseif (!isset($_POST['message']) || $_POST['message'] == "") { writeError("ERROR: You must enter a message (if you don't want to write a message, why are you filling in a support ticket?). Please click the 'Back' button in your browser to fix this."); die(); } else { // Insert the ticket $database->safe_query("INSERT INTO tickets (userID, date, category, subject, severity, lastPost) VALUES (%i, NOW(), %i, '%s', %i, %i)", array($_SESSION['support_id'], $_POST['category'], $_POST['subject'], $_POST['severity'], $_SESSION['support_id']), __FILE__, __LINE__); $ticket_id = $database->get_insert_id(); // Insert the message // NOTE: The actual ticket and the message are stored seperately, so don't get confused here $database->safe_query("INSERT INTO ticket_messages (date, message, ticketID, userID) VALUES (NOW(), '%s', %i, %i)", array(nl2br(htmlentities($_POST['message'])), $ticket_id, $_SESSION['support_id']), __FILE__, __LINE__); // Get the body of the email $message = newTicketMail($_SESSION['support_id'], stripslashes($_POST['subject']), $_POST['severity'], stripslashes($_POST['message'])); // Send the actual email mail($SETTINGS['adminEmail'], "New support ticket (ID #{$ticket_id})", $message, "From: {$SETTINGS['fromEmail']}"); pageHeader("Ticket Received"); echo "Your ticket was received by our support team and we will reply as soon as possible.<br /><br /><a href='index.php?page=ticket_main'>back</a>"; } // If the form hasn't been submitted yet } else { pageHeader("Submit a Support Ticket"); // Get the category list $cat_list = showTicketCategories(false, "name ASC", 0); // Get the severity list $severities = showTicketSeverities(false); // Show the input form echo <<<EOT If you would like to submit a support ticket to our support team, please use the form below. We will try to reply as soon as possible.<br /><br /> <form action='index.php?page=ticket_submit' method="post" name="adminForm"> <input type='hidden' name='submit2' value='true' /> Subject: <input type='text' name='subject' size='40' /><br /> Category: <select name='category'>{$cat_list}</select><br /> Severity: {$severities}<br /> Teacher Name:<input type='text' name='subject' size='40' /><br /> Room Number:<input type='text' name='subject' size='40' /><br /> Message: EOT; outputBBCEditor("message", "Type your message here"); echo "<input type='submit' value='Submit Ticket' /> </form>"; } ?> Line that should be looked at I think <form action='index.php?page=ticket_submit' method="post" name="adminForm"> <input type='hidden' name='submit2' value='true' /> Subject: <input type='text' name='subject' size='40' /><br /> Category: <select name='category'>{$cat_list}</select><br /> Severity: {$severities}<br /> Teacher Name:<input type='text' name='subject' size='40' /><br /> Room Number:<input type='text' name='subject' size='40' /><br /> Message: Teacher room name & room number I would like to if the user doesn't put the teacher name or room number when they go to submit it it would say like on a popup Please Enter The Required fields Quote Link to comment https://forums.phpfreaks.com/topic/69701-php-required-field/ Share on other sites More sharing options...
freakstyle Posted September 17, 2007 Share Posted September 17, 2007 hey there, your form fields are using the same name which wouldn't be helpful for validation. i would suggest renaming them, ex: <?php if ( !isset($_POST['subject']) || is_null($_POST['subject']) ) { echo 'error!'; } ?> Teacher Name:<input type='text' name='teacher_name' size='40' /><br /> Room Number:<input type='text' name='room_number' size='40' /><br /> good luck Quote Link to comment https://forums.phpfreaks.com/topic/69701-php-required-field/#findComment-350217 Share on other sites More sharing options...
Zer0Cam Posted September 18, 2007 Author Share Posted September 18, 2007 Teacher Name:<input type='text' name='teacher_name' size='40' /><br /> Room Number:<input type='text' name='room_number' size='40' /><br /> Are there just as a place holder, I'am trying to figure out how to make them required fields Quote Link to comment https://forums.phpfreaks.com/topic/69701-php-required-field/#findComment-350222 Share on other sites More sharing options...
freakstyle Posted September 18, 2007 Share Posted September 18, 2007 sorry i didn't replace the actual code i was trying to show you. doh. so, you say you want to require a user to input data? the process : user submits form :> process page checks input against your rules/logic :> form redirects thank you or error :> code ex: <?php if ( isset($_POST) ) : $Errors = null; if ( !isset($_POST['teacher_name']) || is_null($_POST['teacher_name']) ) : $Errors['teacher_name'] = 'you must enter a teachers name' ; endif ; if ( !isset($_POST['room_number']) || is_null($_POST['room_number']) ) : $Errors['teacher_name'] = 'you must enter a room number' ; endif ; if ( !is_null( $Errors ) ) : //redirect back with errors... //( i prefer to use sessions to transfer the error messages back to the form, using the url where the submission came from ) else : //redirect to page with thank you message. endif; the basic idea is to define what your validating, ie should there be some data, how much data? is it an email. yadda yadda yadda. then check for it. in my validation i always check that the post is found, and that there is no injection in any field, or someone trying to dump a script in there. if you would like me to post the source of my validation class, a process page and a form page, let me know i don't mind. good luck, and let me know if i've missed the mark again. Quote Link to comment https://forums.phpfreaks.com/topic/69701-php-required-field/#findComment-350282 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.