PHP - Isset On Form Submission Not Working!
I've tried both of these methods, but neither are working. The if statement fails every time.
Code: [Select] if(isset($_POST['submit'])){ Code: [Select] if(isset($submit)){ This is the form: Code: [Select] <form id="form1" name="form1" method="post" action="join.php"> <label><span> <input name="email" type="text" class="keywords" id="textfield" maxlength="50" value="Join my mailing list..." onclick="make_blank();" /> </span> <input name="submit" type="image" src="images/search.gif" class="button" onclick="return checkmail(this.form.email);"/> </label> </form> Similar TutorialsHi I have a from, now after the users send the form, i want to redirect to a thank you page. my code does not redirect and gives me this error Warning: Cannot modify header information - headers already sent by (output started at D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php:1) in D:\inetpub\vhosts\feelmalaysia.com\httpdocs\sendmailsqlar.php on line 25 I have the redirect page saved in the same directory as the php file. my Php Code : <?php $headers .= 'Content-type: text/plain; charset=UTF-8; format=flowed' . "\r\n"; $headers .= 'Content-Transfer-Encoding: 8bit'."\r\n"; $to = "xxx@xxx.com"; $visitor = $_REQUEST['Name'] ; $visitormail = $_REQUEST['Email'] ; $nationality = $_REQUEST['Nationality'] ; $stulevel = $_REQUEST['Level'] ; $stfield = $_REQUEST['Field'] ; $message = $_REQUEST['Message'] ; $header = "From: $visitormail\n" . "Reply-To: $visitormail\n"; $subject = "Arab Enquiry"; $message = "From: $visitor \n\n Email: $visitormail \n\n Nationality: $nationality \n\n Level: $stulevel \n\n Field: $stfield \n\n Message: $message"; mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header, $headers); //Sending auto respond Email to visitor $reply_header = "From: xxx@xxx.com\n" . "Reply-To: xxx@xxx.com\n"; $reply_subject = "- تم استلام طلبكم"; $reply_to = "$visitormail"; $reply_message = "$visitor \n\n شكرا لزيارتكم موقعنا . \n نود ابلاغكم بأنه تم استلام طلبكم وسوف يتم الرد عليكم قريبا.\n هذه الرسالة مرسلة من نظام الموقع.\n شكرا\n "; mail($reply_to, '=?UTF-8?B?'.base64_encode($reply_subject).'?=', $reply_message, $reply_header, $headers); header('Location: thankyouar.html'); ?> Please help . Thank you Code: [Select] if (isset($_COOKIE['hide_div']['0']) && isset($_COOKIE['hide_div']['2'])){ $cookie1 = $_COOKIE['hide_div']['0']; $cookie2 = $_COOKIE['hide_div']['2']; } if ($cookie1 == $cat_id OR $cookie2 == $cat_id) { foreach ($this->forums as $forum_id => $forum_data) { if ($forum_data['category'] == $cat_id) { //----------------------------------- // We store the HTML in a temp var so // we can make sure we have cats for // this forum, or hidden forums with a // cat will show the cat strip - we don't // want that, no - we don't. //----------------------------------- $temp_html .= $this->process_forum($forum_id, $forum_data); } } if ($temp_html != "") { $this->output .= $this->html->CatHeader_Expandedhidden($cat_data); $this->output .= $this->html->end_this_cat(); } unset($temp_html); }else{ $cookie1 = ''; $cookie2 = ''; why in the world is it displaying Undefined variable: cookie1 and cookie2 as errors? When I declared both of them even AFTER my if statement, this is bogus dude, lol this isset stuff is really confusing or am i just not doing it right? Im trying to use an if isset to stop my error messages displaying before they submit the form it worked on another part of my website but wont work for this, It just wond submit the form at all when i click submit here is the code: <html> <head> </head> <body> <form action="contact.php" method="post"> <fieldset> <legend>Contact Us</legend> Your Email:*<br> <input type="text" name="email"><br> Subject:*<br> <select name="subject"> <option value=""></option> <option value="1">Recruitment</option> <option value="2">Absense</option> <option value="3">Enquiry</option> </select> <br> Message:*<br> <textarea name="message" cols="50" rows="5"></textarea><br> <?php require_once('recaptchalib.php'); $publickey = "6LeB8LwSAAAAAKwvC3HWJNwWw9vYiSEkvFEvDduD"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <br> <input type="submit" value="Send Email"> </form> Required fields are marked with a *<br><br> <?php if(isset($_POST['Submit'])){ $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = "nathan_k_boothby_1994@hotmail.co.uk"; //checcking that all relevent information is entered and correct if(!$message || !$email) { $errmessage ="Please fill in all required data."; } require_once('recaptchalib.php'); $privatekey = "6LeB8LwSAAAAAA_0IIEnAxL5uOau0TBm83Iog7Ey"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { $errmessage ="The text you wrote did not match the image."; } //Sending the email if nothing is wrong if(!$errmessage) { header("location:send.php?to=".$to."&subject=".$subject."&email=".$email."&message=".$message.""); }else{ echo $errmessage; } } ?> </fieldset> <br><br><br> </body> </html> And here is a link to the page: http://valiantflight.comlu.com/emailer/contact.php Any help will be greatly appriciated, Thanks, Blink359 The below should be making it so that in order for "customer reviews" to be visible, you should need the "&review" in the url, but it's coming up regardless if it's in the URL or not. http://ghosthuntersportal.com/store.php?product=2 Code: [Select] elseif(isset($_GET['product'])){ $product_id=$_GET['product']; $sql500="SELECT * FROM $tbl_name3 WHERE product_id='$product_id'"; $result500=mysql_query($sql500); $num_rows500=mysql_num_rows($result500); if($num_rows500==0){ $average_rating=0; } else{ while($row500=mysql_fetch_array($result500)){ extract($row500); $total = $total + $review_product_rating; $review.=' <div class="review_container"> <div>'.$review_product_rating.' '.$review_title.'</div> <div>By '.$review_name.' from '.$review_location.' on '.$review_date.'</div> <div>Pros: </div><div>'.$review_pros.'</div> <div>Cons: </div><div>'.$review_cons.'</div> <div>Describe Yourself: </div><div>'.$review_describe.'</div> <div>Best Use: </div><div>'.$review_best_use.'</div> <div>'.$review_text.'</div> </div> '; } $review_product_rating_total=$total; $average_rating=$review_product_rating_total/$num_rows500; } $sql50="SELECT * FROM $tbl_name WHERE product_id='$product_id'"; $result50=mysql_query($sql50); while($row50=mysql_fetch_array($result50)){ extract($row50); $section=ucwords($product_category); $product_name=ucwords($product_name); $crumbs='<a href="./index.php">Home</a> <span class="eleven">></span> <a href="./store.php?cat='.$product_category.'">'.$section.'</a> <span class="eleven">></span> <a href="./store.php?product='.$product_id.'">'.$product_name.'</a>'; $section=" - ".$section; $product_highlights=str_replace("[","<li>", $product_highlights); $product_highlights=str_replace("]","</li>", $product_highlights); $content.=' <div class="product_wrapper"> <div>'.$product_name.'</div> <div class="product_image"> <div><img src="'.$product_image.'" alt="'.$product_name.'" /></div> </div> <div class="product_details"> <div class="product_price">Price: $'.$product_price.'</div> <div class="product_code">GHP#: '.$product_code.'</div> <div class="rating_image">'; if($num_rows500==0){ $content.='No Rating'; } else{ $content.='<img src="'.$average_rating.'.png" alt="'.$average_rating.'" />'; } $content.=' <span class="twelve">('.$num_rows500.' Reviews)</span></div><div>'; if(isset($product_highlights)){ $content.='<div class="product_highlights_text">Product Highlights</div><div class="product_highlights_item"><ul>'.$product_highlights.'</ul></div>'; } else{ } $content.='</div> </div> </div> '; } $content.='<div class="product_links_headers">Overview | Specifications | Customer Reviews</div>'; if(isset($review)){ $content.='<div style="margin-top: 400px;">'.$review.'</div>'; } elseif(isset($specifications)){ $content.='<div style="margin-top: 400px;">'.$product_specifications.'</div>'; } else{ } } Hi there, I have just move hosts with our website and it loads the frontpage but non of the subsequent pages. The site works like this, depending on the variables in the address depends which page and which template are loaded into it. If the template is "ros" it loads rosettes template, if it is "tro" it loads trophy template, and then the name of the item, ie "hazel" will load up the hazel product page. All it is doing at the moment is loading the home.php page. The code to do this is below: <? if (!isset($template)) {include ("static/home.php");} else if (isset($id)) { if (!file_exists("site_templates/$template.php")) { echo "OOPS! <P> The template you have requested does not exist!<BR><BR><BR><BR><BR><BR>"; }elseif (file_exists("site_templates/$template.php")) { include ("site_templates/$template.php"); } } ?> It worked with our last host, but refuses to work now. Is there someone out there that can help. Thanks in advance, Phil For some reason the !isset() function doesnt seem to work i cant find out why hope you guys will be able to help Here is the html code for the form where the user enters the data Code: [Select] <div id="contact_form"> <h2>On Site SEO Signup Form</h2> <form method="post" name="contact" action="http://www.techbreeze.in/freeseo.php"> <label for="uname">Name:</label> <input name="uname" type="text" class="required input_field" id="uname" /> <div class="cleaner h10"></div> <label for="email">Email:</label> <input type="text" class="validate-email required input_field" name="email" id="email" /> <div class="cleaner h10"></div> <label for="website">Website:</label> <input type="text" class="required input_field" id="website" name="website"/> <div class="cleaner h10"></div> <label for="ftp">Your FTP Login URL:</label> <input type="text" class="required input_field" id="url" name="url" /> <div class="cleaner h10"></div> <label for="username">Your FTP Username:</label> <input type="text" class="required input_field" id="user" name="user" /> <div class="cleaner h10"></div> <label for="password">Your FTP Password:</label> <input type="password" class="required input_field" id="pass" name="pass"/> <div class="cleaner h10"></div> <input type="submit" value="Send" id="submit" name="submit" class="submit_btn float_l" /> <input type="reset" value="Reset" id="reset" name="reset" class="submit_btn float_r" /> </form> </div> And here is the code for the .php file where the !isset() function is used Code: [Select] <?php // validation expected data exists if( !isset($_POST['uname'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Name" field empty!'); } if( !isset($_POST['pass'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Password" field empty!'); } if( !isset($_POST['email'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Email" field empty!'); } if( !isset($_POST['website'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Website" field empty!'); } if( !isset($_POST['url'])) { die ('We are sorry, but all the fields are necessary you cant leave the "FTP URL" field empty!'); } if( !isset($_POST['user'])) { die ('We are sorry, but all the fields are necessary you cant leave the "Username" field empty!'); Thanks in advance Sorry for the miss spell on correctly counldn't edit the title
I need to have the following 3 varibles checked to see if they are set and if not display an error saying "All fields need to be filled in." My problem is that it's not working. Did I mess up on my if statement? $tempneeded $lowtemp $gallons <?php $tempneeded = $_POST['tempneeded']; $lowtemp = $_POST['lowtemp']; $gallons = $_POST['gallons']; htmlspecialchars($tempneeded, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($lowtemp, ENT_QUOTES, 'UTF-8') . ' ' . htmlspecialchars($gallons, ENT_QUOTES, 'UTF-8') . ' ' . $wgd = .5; $tempdiff = $tempneeded - $lowtemp; $wattsneeded = $tempdiff * ($gallons * $wgd); if (!isset ($lowtemp,$tempneeded,$gallons)) { echo "<b>All fields need to be filled in.</b>"; } else { echo "<b>You will need a total of $wattsneeded watts to rasie your tempature $tempdiff degress, from $lowtemp to $tempneeded.</b></td></tr>"; } ?> Edited by msebar, 08 October 2014 - 01:43 PM. I have a simple log in form. By debugging I found that isset post submit function is not responding. It remains on the same page after submitting form. I have googled all the possible solutions to this problem but none worked. Any help is greatly appreciated. The form is in multiplelogin.php file and the code is in multi.php file. After login redirection is to teachers.php file. <?php session_start(); $conn = mysqli_connect("localhost", "root", "", "signup");
if(isset($_SESSION['username'])) {
?>
<head> <link rel="stylesheet" type="text/css" href="bootstrap.css"> <title> Teachers Students Login </title> </head> <body class="bg-secondary"> <div class="container"> <div class="row justify-content-center"> <div class="col-log-5 bg-light mt-5 px-0"> <h3 class="text-center text-light bg-primary py-3 px-5"> Log In </h3>
<div class="form-group px-5"> <input type="email" name="email" class="form-control form-control-lg" placeholder="Email" required> </div> <div class="form-group px-5"> <input type="password" name="password" class="form-control form-control-lg" placeholder="Password" required> </div> <div class="form-group px-5"> <input type="submit" name="submit" value="Submit" class="btn btn-primary btn-block"> </div> </form> </div> </div> </div>
<?php
ini_set( 'display_errors', 1 );
$password = $_POST['password'];
$stmt = mysqli_stmt_init($conn); header("Location: multilogin.php?error=sqlerror"); exit();
} else { mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if ($pwdCheck == false) {
exit(); $_SESSION['username'] = $row['username']; $_SESSION['email'] = $row['email']; header("Location: teachers.php?login=success");
exit ();
exit();
exit();
else {
exit(); Hello! This may sound like a stupid question but i have been trying to get this working all day and its driving me crazy.
Ive been asked to take over development of this project, he sent me his code and its a little out of date so im trying to update it. Here is what i cant work out.
I have this little snippet of code:
if ($page == "showthread"){ showThread(); }There are several more like that, but you dont need a whole list. That code seems to be throwing up this error when i go to that specific page: Notice: Undefined index: error in ..... All well and good, i would usually do this: if (isset($page) == "showthread"){ showThread(); }Thats fine and dandy, the error goes away. But now, when i go to that page, it redirects me and gives me my error message for a non-existing page. Its really frustrating me. Can you help me fix this little error? soory guys .. actually i am trying to add pagination in script.. but its not pagging.
but when i tried without isset($_get the code worked fine and then i tried to doing with isset($_get for a perticular cat
but its not working. can someone see my code and tell me whats worng i have done.
<!DOCTYPE HTML> <html> <head> </head> <body> <?php // include database connection include 'libs/db_connect.php'; // page is the current page, if there's nothing set, default is page 1 $page = isset($_GET['page']) ? $_GET['page'] : 1; // set records or rows of data per page $recordsPerPage = 1; // calculate for the query LIMIT clause $fromRecordNum = ($recordsPerPage * $page) - $recordsPerPage; // select all data $query = "SELECT * FROM posts ORDER BY post_id desc LIMIT {$fromRecordNum}, {$recordsPerPage}"; /* page and its LIMIT clause looks like: 1 = 0, 5 2 = 5,10 3 = 10,15 4 = 15, 20 5 = 20, 25 */ $stmt = $con->prepare( $query ); $stmt->execute(); //this is how to get number of rows returned $num = $stmt->rowCount(); //check if more than 0 record found if($num>0){ $cat=1; if(isset($_GET['cat'])){ $cat_id = $_GET['cat']; $get_posts = "select * from posts where category_id = '$cat_id'"; $run_posts = mysql_query($get_posts); while($row_posts = mysql_fetch_array($run_posts)){ $post_id = $row_posts['post_id']; $post_title = $row_posts['post_title']; $post_date = $row_posts['post_date']; $post_author = $row_posts['post_author']; $post_image = $row_posts['image']; $post_content = substr($row_posts['post_content'],0,80); echo " <div class='post_area'> <h4> <a href = 'details.php?post=$post_id'>$post_title</a> </h4> <div class='date'><div id='com'> Date</div>$post_date</div><span style='font-size:12px'><i style='color:grey;font-size:10px'>Posted By</i> </b>$post_author</span> <content><img src = '123dondadatest/news_images/$post_image' width = '100' height='100'/> <div>$post_content <br/><a id='rmlink' href = 'details.php?post=$post_id'> Read More...</a></div><br /><br/><br/><br/> </div> "; } } // *************** <PAGING_SECTION> *************** echo "<div id='paging'>"; // ***** for 'first' and 'previous' pages if($page>1){ // ********** show the first page echo "<a href='" . $_SERVER['PHP_SELF'] . "' title='Go to the first page.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> << </span>"; echo "</a>"; // ********** show the previous page $prev_page = $page - 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$prev_page}' title='Previous page is {$prev_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> < </span>"; echo "</a>"; } // ********** show the number paging // find out total pages $query = "SELECT COUNT(*) as total_rows FROM posts"; $stmt = $con->prepare( $query ); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $total_rows = $row['total_rows']; $total_pages = ceil($total_rows / $recordsPerPage); // range of num links to show $range = 2; // display links to 'range of pages' around 'current page' $initial_num = $page - $range; $condition_limit_num = ($page + $range) + 1; for ($x=$initial_num; $x<$condition_limit_num; $x++) { // be sure '$x is greater than 0' AND 'less than or equal to the $total_pages' if (($x > 0) && ($x <= $total_pages)) { // current page if ($x == $page) { echo "<span class='customBtn' style='background:red;'>$x</span>"; } // not current page else { echo " <a href='{$_SERVER['PHP_SELF']}?page=$x' class='customBtn'>$x</a> "; } } } // ***** for 'next' and 'last' pages if($page<$total_pages){ // ********** show the next page $next_page = $page + 1; echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$next_page}' title='Next page is {$next_page}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> > </span>"; echo "</a>"; // ********** show the last page echo "<a href='" . $_SERVER['PHP_SELF'] . "?page={$total_pages}' title='Last page is {$total_pages}.' class='customBtn'>"; echo "<span style='margin:0 .5em;'> >> </span>"; echo "</a>"; } echo "</div>"; // ***** allow user to enter page number echo "<form action='" . $_SERVER['PHP_SELF'] . "' method='GET'>"; echo "Go to page: "; echo "<input type='text' name='page' size='1' />"; echo "<input type='submit' value='Go' class='customBtn' />"; echo "</form>"; // *************** </PAGING_SECTION> *************** } // tell the user if no records were found else{ echo "<div class='noneFound'>No records found.</div>"; } ?> </body> </html> Hey Guys, Im working with a form and need some help. So at the moment i have got it working so that if the user doesn't select the values from the drop down list, an error will occur saying 'Please select all fields'. What i want to do now is make it so that if this error occurs, the value of the drop down list will stay as it is an NOT reset. Could someone help me out? * Note that the code below is currently ok, basically it checks if there is a value, if not it will say "Select Player". Code: [Select] <td>Prop</td> <td><select name="prop1" style="width: 150px"> <option value="<? echo $row['prop1']; ?>"><? if (empty($row['prop1'])) { echo "Select Player"; } else { echo $row['prop1']; } ?></option> <?php echo $option_str; ?> </select></td> <td>16.</td> <td><select name="r16" style="width: 150px"> <option value="<? echo $row['r16']; ?>"><? if (empty($row['r16'])) { echo "Select Player"; } else { echo $row['r16']; } ?></option> <?php echo $option_str; ?> </select></td> Hi all, Hoping someone can help with what i would guess is a very simple problem. I have the following code which is suppose to display a form. the form posts to itself and uses isset and if the form has been posted it doesnt display the form. if (isset($_POST['submit'])) { echo "question submitted successfully"; } else { echo '<form method="post" name="qanda" id="qanda" action="http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] . '">'; echo '<p><label for="name">Name</label> <input type="text" id="name" /></p>'; echo '<p><label for="e-mail">E-mail</label> <input type="text" id="e-mail" /></p>'; echo '<p><label for="Question">Question</label> <textarea rows="6" id="question"></textarea></p>'; echo '<p class="submit"><input type="submit" value="Submit" /></p></form>'; } this currently doesnt work. Extra things you might need to know is that this script/form is an included file in a dynamic site which also uses the rewrite module which is why I am using http://' . $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"] just incase that makes a difference. I have a form that is supposed to use PHP to display errors next to incomplete form fields when the form is submitted. But I am never getting into my PHP loop. I tried using the print_r(true) function to debug, but no luck. When I click submit I see this i the URL... http://localhost/00_MyWebSite/zzEmptyPHP.php?firstName=&lastName=&submit=Process+Order&submitted=true which is what I would expect on a blank form being submitted. Here is my code... Code: [Select] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link type="text/css" rel="stylesheet" href=".css"> <style type="text/css" > form{ width: 400px; margin: 0 auto; } </style> </head> <body> <?php // Initialize. $errors = array(); $errors['firstName'] = ''; $errors['lastName'] = ''; $firstName = $lastName = ''; echo "print_r = " . print_r(true); if (isset($_POST['submit'])){ // Handle Form. // Trim all incoming data. $trimmed = array_map('trim', $_POST); // Check First Name. if (preg_match('/^[A-Z\'.-]{2,20}$/i', $_POST['firstName'])){ $firstName = $_POST['firstNamae']; }else{ $errors['firstName'] = 'Please enter your First Name.'; } // Check Last Name. if (preg_match('/^[A-Z\'.-]{2,20}$/i', $_POST['lastName'])){ $lastName = $_POST['lastName']; }else{ $errors['lastName'] = 'Please enter your Last Name.'; } // if there are errors then go back to the form and display them }else{ } ?> <form action=""> <fieldset> <legend>Billing Details</legend> <ol> <li> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" class="text" type="text" /> <?php echo $errors['firstName']; ?> </li> <li> <label for="lastName">Last Name:</label> <input id="lastName" name="lastName" class="text" type="text" /> <?php echo $errors['lastName']; ?> </li> </ol> <input type="submit" name="submit" value="Process Order" /> <input type="hidden" name="submitted" value="true" /> </fieldset> </form> </body> </html> Any ideas what I am doing wrong? Thanks, Debbie I'm trying to figure out where my problem is. Its not submitting my form. I'm getting the alert but when it submits it does the url?variables=whatever deal. Code: [Select] <?php require ('php/eventnames.php'); ?> <script type="text/javascript" src="forms/addnew/js/eventnames.js"></script> <!-- Form --> <form action="#" id="eventNameForm" > <fieldset> <legend>Add New Event Name</legend> <div class="field required"> <label for="eventName">Event Name</label> <input type="text" class="text" name="eventName" id="eventName" title="Event Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="shortName">Event Short Name</label> <input type="text" class="text" name="shortName" id="shortName" title="Event Short Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="eventType">Event Type</label> <select class="dropdown" name="eventType" id="eventType" title="Event Type"> <option value="">- Select -</option> <?php $eventTypes = array('Singular', 'Recurring', 'Pay Per View'); foreach($eventTypes as $et): ?> <option value="<?php echo $et; ?>"><?php echo $et; ?></option> <?php endforeach; ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="hidden" name="userID" id="userID" value="<?php echo $userID; ?>" /> <input type="submit" class="submit" name="submitEventName" id="submitEventName" title="Submit Event Name" value="Submit Event Name"/> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Content Page was added to the database.</p> </div> Code: [Select] $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); alert("Test Alert!"); ("#eventNameForm").validate({ rules: { eventName: { required: true }, shortName: { required: true }, eventType: { required: true, rangelength: [1] } }, messages: { eventName: "Please enter the event name!", shortName: "Please enter the event's short name!", eventType: "Please enter the event type!" }, submitHandler: function(form) { var userID = $("input#userID").val(); var eventName = $("input#eventName").val(); var shortName = $("input#shortName").val(); var eventType = $("select#eventType").val(); var dataString = 'userID=' + userID + '&eventName=' + eventName + '&shortName=' + shortName + '&eventType=' + eventType + '&submitEventName=True'; $.ajax({ type: "POST", url: "processes/eventnames.php", data: dataString, success: function(myNewVar) { if (myNewVar == 'good') { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>" + eventName + " Page saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow"); $(':input','#eventNameForm') .not(':submit, :hidden') .val(''); } else if (myNewVar == 'bad1') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + eventName + " already exists in the database.</p>"); $("div.message-error").show(); } else if (myNewVar == 'bad2') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + shortName + " already exists in the database.</p>"); $("div.message-error").show(); } else if (myNewVar == 'bad3') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + eventName + " and " + shortName + " already exists in the database.</p>"); $("div.message-error").show(); } } }); return false; } }); });
Hi All, ## First Document if(!empty($_FILES["dc1"])){ $fileName1 = htmlspecialchars_decode((basename($_FILES["dc1"]["name"]))); $fileTypeA1 = pathinfo($fileName1, PATHINFO_EXTENSION); $targetFilePath1 = $uploadDir . $uID . '-' . $randnum . '.' .$fileTypeA1; if(move_uploaded_file($_FILES["dc1"]["tmp_name"], $targetFilePath1)){ $uploadedFile1 = $targetFilePath1; } } ## Second Document if(!empty($_FILES["dc2"])){ $fileName2 = htmlspecialchars_decode((basename($_FILES["dc2"]["name"]))); $fileTypeA2 = pathinfo($fileName2, PATHINFO_EXTENSION); $targetFilePath2 = $uploadDir . $uID . '-' . $randnum . '.' .$fileTypeA2; if(move_uploaded_file($_FILES["dc2"]["tmp_name"], $targetFilePath2)){ $uploadedFile2 = $targetFilePath2; } } Edited October 13, 2020 by SH1989 Clean code up Where should my Form go once it is submitted? I am reading through some old code, and I was using some pretty convoluted programming to get everything (e.g. error and success messages after form submittal) to work. Basically what I would do was... Code: [Select] HTML to Open Page PHP to Handle Form If Data Okay... Success Message (e.g. "Your account was created!") HTML to close out Page If Data Invalid... Failure Message (e.g. "A System Error occurred. Please contact the Administrator.") HTML to close out Page HTML Form HTML to Close Page I have heard that you should always put your PHP first in the script and then follow it up with your HTML Page and Form. But where should you go once the form is submitted? My second attempt at things - to fix the mess above - was to REDIRECT the user to a "Handling Page" which basically was a large case statement that would read a "processing code" and display the right message. But that seems kind of hokey too?! Can someone help me come up with a more professional and scalable solution?? Thanks, Debbie Hi, I have a form on my page. <form id="advanced_search" name="advanced_search" method="POST" action="<?php echo $PHP_SELF;?>"> </form> Form submits with a regular button <input type="submit" name="advSearch" id="advSearch" value="Search" /> And i have a detector to see where submit button has been clicked on my next page: if(isset($_POST['advSearch'])) { echo "Button was clicked"; } However, I wanted a custom button for better styling and control. So i replaced my regular button with this now which uses javascript to submit the form. <a class="button" href="javascript:document.advanced_search.submit()" name="advSearch" id="advSearch"><span>Search</span></a> Now the isset($_POST) is not working anymore. Can anyone help please?? Thanks! I'm having a few issues with a serach function in Internet Explorer, it works fine in firefox which is very annoying. What basically is happening, is the a form is sumbitting and posting info across, but on itself and then this is transfered into a php variable which is used on the query. Default values have been assigned if the isset of the form is not true. So I believe the issue is occuring on the " if(isset($_POST['submit'])) " but as stated it works perfectly fine in firefox. Any suggestions? Code: [Select] <?php print " <form target='_self' method='POST'> <table class=''> <tr> <td> <input name='vehicle' type='text' id='search_name' size='16'> <input type='image' src='images/search.gif' alt='Search' name='submit' id='search' value='Search'/> </td> </tr> <tr> <td> <select name='filter' id='filter'> <option value='make' selected='selected'>Filter By</option> <option value='make'>Vehicle Manufacture</option> <option value='model'>Vehicle Model</option> <option value='our_price'>Price</option> <option value='delivery_time'>Delivery Time</option> </select> </td> </tr> <tr> <td> <input type='radio' name='direction' value='ASC' checked/>Ascending <input type='radio' name='direction' value='DESC' />Descending </td> </tr> </form> "; include "connections/dbconnect.php"; if(isset($_POST['submit'])) { $vehicle = $_POST['vehicle']; $filter = $_POST['filter']; $direction = $_POST['direction']; //$rowsPerPage = $_POST['limit']; } else { $filter = "make"; $direction = "ASC"; } //$manfactures = "Ford"; if(isset($_GET['limit'])) { $rowsPerPage = $_GET['limit'];; } else { // how many rows to show per page $rowsPerPage = 10; } // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $car_query = " SELECT * FROM cars WHERE model LIKE '%$vehicle%' OR make LIKE '%$vehicle%' OR model_details LIKE '%$vehicle%' OR search LIKE '%$vehicle%' ORDER BY $filter $direction LIMIT $offset, $rowsPerPage"; $car_result = mysql_query($car_query) or die ("Error in query: $car_query. ".mysql_error()); setlocale(LC_MONETARY, 'en_GB'); $fmt = '%i'; // how many rows we have in database $query = "SELECT COUNT(model) AS numrows FROM cars"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page&limit=$rowsPerPage\">$page</a> "; } } if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page&limit=$rowsPerPage\">[Prev]</a> "; $first = " <a href=\"$self?page=1&limit=$rowsPerPage\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page&limit=$rowsPerPage\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage&limit=$rowsPerPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } if (mysql_num_rows($car_result) > 0) { ...... bringing back all the information from the database Hi. Link to project: www.smarttreff.moo.no Login user: admin login pw: 123 When i login the login form wont disapear. If i return to the index(Hjem) page without logging out, the loginform disapear. I am ussing session for the login So the basicly, i want the loginform do disapear at once when the user has pushed login button(Logg in) (dont laught at my "cut and past" for the include meny.. i just made the design and chopped it to bits and put it into includes) Index.php Code: [Select] <?php session_start(); include("css.php"); include("header.php"); include("meny.php"); ?> <td width="596" valign="top"><table width="100%" border="0" cellpadding="15"> <tr> <td class="tabell" valign="top" align="left"> Main </td> </tr> </table></td> </tr> </table> <?php include("footer.php"); ?> meny.php Code: [Select] <table width="800" border="0"> <tr> <td width="198" valign="top"><table width="100%" border="0" cellpadding="15"> <tr> <td align="left" valign="top" class="tabell"> <a href="index.php">Hjem</a> <br /> Når og hvor <br /> For hvem <br /> Spørsmål og svar<br /> Forum <br /> <br /> <br /> Samarbeidspartnere </td> </tr> </table> <br /> <table width="100%" border="0" cellpadding="15"> <tr> <td class="tabell" valign="top" align="left"> <?php if(isset($_SESSION['username'])) echo "Velkommen, " .$_SESSION['username']. "!<a href='innlogget.php'>Medlemsnyheter</a><br><a href='logout.php'>Log ut</a>"; else { include("loginform.php"); } ?> </td> </tr> </table></td> <td width="15"> </td> Okay, so I have a neat little website and I'm having some issue with some quality-of-life improvements.
Namely, the user clicks a button which starts a server-side operation that can take up to 20 to 30 seconds.
I want a little message to appear below the button that says, "Operation started. This may take upwards of 20 to 30 seconds depending on traffic."
As of now, I have the typical
<form action="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> ... <input type="submit" name="submit" value="Make PDF" /> </form> <?php if (isset($_POST["submit"])) { ... } ?>The only problem is, part of my PHP code must communicate with a Java server that I have running on the server itself. So how the site works is, there's the computer I'm renting out and it's running Apache and a custom Java server I wrote myself. Apache handles the web request and upon form submission, PHP opens a socket with the Java server and begins the task. PHP then waits for the connection to close. |