PHP - Display Message On Form Submit
how do I make it so that $message displays on form submit on the same page?:
Code: [Select] <?php session_start(); // Must start session first thing /* Created By Adam Khoury @ www.flashbuilding.com -----------------------June 20, 2008----------------------- */ // Here we run a login check if (!isset($_SESSION['id'])) { echo 'Please <a href="login.php">log in</a> to access your account'; exit(); } //Connect to the database through our include include_once "connect_to_mysql.php"; // Place Session variable 'id' into local variable $userid = $_SESSION['id']; ?> <?php $message ='Registration has been verified!'; // Process the form if it is submitted if ($_POST['submit']) { $verified = $_POST['verified']; $sql = mysql_query("UPDATE Events SET verified='yes', WHERE barcode='$verified'"); exit(); } // close if post ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM members WHERE userid='$userid'"); while($row = mysql_fetch_array($sql)){ $userid = $row["userid"]; $name = $row["name"]; $phone = $row["phone"]; $username = $row["username"]; $address = $row["address"]; $city = $row["city"]; $state = $row["state"]; $zip = $row["zip"]; $cell = $row["cell"]; $email = $row["email"]; $accounttype = $row["accounttype"]; $rank = $row["rank"]; $badges = $row["badges"]; $password = $row["password"]; $password2 = $row["password2"]; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template2.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <!-- InstanceBeginEditable name="doctitle" --> <title>Untitled Document</title> <!-- InstanceEndEditable --> <style type="text/css"> #editregion { position:absolute; left:-8px; top:272px; width:1293px; height:51px; z-index:1; text-align: center; clear: none; float: none; } body { background-image: url(file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/button/boyscout1.png); background-repeat: no-repeat; position: relative; } #menu { position:relative; left:160px; top:0px; width:931px; height:59px; z-index:19; } #menu #MenuBar1 li a { color: #000; border-top-style: outset; border-right-style: outset; border-bottom-style: outset; border-left-style: outset; width: 100px; } #status { position:relative; left:16px; top:180px; width:124px; height:44px; z-index:14; } </style> <script src="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/SpryAssets/SpryMenuBar.js" type="text/javascript"></script> <script type="text/javascript"> function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } </script> <!-- InstanceBeginEditable name="head" --> <style type="text/css"> body { background-image: url(file:///Macintosh%20HD/Users/aaron/Downloads/memberSystemBasic%204/button/boyscout1.png); background-repeat: no-repeat; } </style> <!-- InstanceEndEditable --> <!-- InstanceParam name="id" type="text" value="apDiv6" --> <link href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> <style type="text/css"> #logout { position:relative; left:0px; top:0pxpx; width:134px; height:38px; z-index:20; font-weight: bold; font-size: 24px; } #logout a { color: #000; } #status { text-align: center; } #logout1 { position:absolute; left:1071px; top:191px; width:224px; height:61px; z-index:2; } #menu2 { position:absolute; left:-1px; top:172px; width:497px; height:92px; z-index:20; } #footer { position:fixed; left:-10px; top:0px2 width:1290px; height:63px; z-index:1; color: #000; background-color: #000; right: 0px; bottom: 0px; } </style> </head> <body> <div id="logout1"><div id="logout"><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/logout.php">Logout</a></div></div> <div id="status"><?php echo "$accounttype"; ?> <br /><?php echo "$name"; ?> <p> </p> </div> <div id="editregion"><!-- InstanceBeginEditable name="EditRegion3" --> <p> </p> <form id="form1" name="form1" method="post" action=""> Please enter verification code: <label for="verified"></label> <input type="text" name="verified" id="verified" /> </form> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <p> </p> <!-- InstanceEndEditable --><br /><br /> <?php if ($accounttype == "Admin") {echo '<div id="footer"><img src="footer_admin.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="10,5,112,32" href="myprofile.php" /> <area shape="rect" coords="153,5,235,31" href="register.php" /> <area shape="rect" coords="277,7,333,32" href="news.php" /> <area shape="rect" coords="471,7,682,33" href="scoutmanager.php" /> <area shape="rect" coords="726,5,874,34" href="membermanager.php" /> <area shape="rect" coords="906,3,1058,34" href="eventmanager.php" /> <area shape="rect" coords="1092,6,1226,32" href="newsmanager.php" /> </map> </div>'; } else if ($accounttyp="scout"){echo '<div id="footer"><img src="footer_scout.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="526,6,632,34" href="myprofile.php" /> <area shape="rect" coords="668,5,752,32" href="register.php" /> <area shape="rect" coords="789,5,850,34" href="news.php" /> </map> </div>';} else {echo '<div id="footer"><img src="footer_admin.png" width="1290" height="63" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="10,5,112,32" href="myprofile.php" /> <area shape="rect" coords="153,5,235,31" href="register.php" /> <area shape="rect" coords="277,7,333,32" href="news.php" /> <area shape="rect" coords="471,7,682,33" href="scoutmanager.php" /> <area shape="rect" coords="726,5,874,34" href="membermanager.php" /> <area shape="rect" coords="906,3,1058,34" href="eventmanager.php" /> <area shape="rect" coords="1092,6,1226,32" href="newsmanager.php" /> </map> </div>'; } ?></div> <div id="menu2"><div id="menu"> <ul id="MenuBar1" class="MenuBarHorizontal"> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/myprofile.php">My Profile</a> </li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/register.php">Register</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/projects.php">Projects</a> </li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/news.php">News</a></li> <?php if ($accounttype == "Admin") { ?> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/membermanager.php">Scout Manager</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/eventmanager.php">Event Manager</a></li> <li><a href="file:///Macintosh HD/Users/aaron/Downloads/memberSystemBasic 4/newsmanager.php">News Manager</a></li> </ul><?php } ?> </div></div> <script type="text/javascript"> var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"}); </script> </body> <!-- InstanceEnd --></html> Similar TutorialsHello, I have coded a contact form in PHP and I want to know, if according to you, it is secure! I am new in PHP, so I want some feedback from you. Moreover, I have also two problems based on the contact form. It is a bit complicated to explain, thus, I will break each of my problem one by one. FIRST:The first thing I want to know, is if my contact form secure according to you: The HTML with the PHP codes: Code: [Select] <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { //Assigning variables to elements $first = htmlentities($_POST['first']); $last = htmlentities($_POST['last']); $sub = htmlentities($_POST['subject']); $email = htmlentities($_POST['email']); $web = htmlentities($_POST['website']); $heard = htmlentities($_POST['heard']); $comment = htmlentities($_POST['message']); $cap = htmlentities($_POST['captcha']); //Declaring the email address with body content $to = 'alithebestofall2010@gmail.com'; $body ="First name: '$first' \n\n Last name: '$last' \n\n Subject: '$sub' \n\n Email: '$email' \n\n Website: '$web' \n\n Heard from us: '$heard' \n\n Comments: '$comment'"; //Validate the forms if (empty($first) || empty($last) || empty($sub) || empty($email) || empty($comment) || empty($cap)) { echo '<p class="error">Required fields must be filled!</p>'; header ('refresh= 3; url= index.php'); return false; } elseif (filter_var($first, FILTER_VALIDATE_INT) || filter_var($last, FILTER_VALIDATE_INT)) { echo '<p class="error">You cannot enter a number as either the first or last name!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Incorrect email address!</p>'; return false; } elseif (!($cap === '12')){ echo '<p class="error">Invalid captcha, try again!</p>'; return false; } else { mail ($to, $sub, $body); echo '<p class="success">Thank you for contacting us!</p>'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <p>Your first name: <span class="required">*</span></p> <p><input type="text" name="first" size="40" placeholder="Ex: Paul"/></p> <p>Your last name: <span class="required">*</span></p> <p><input type="text" name="last" size="40" placeholder="Ex: Smith"/></p> <p>Subject: <span class="required">*</span></p> <p><input type="text" name="subject" size="40" placeholder="Ex: Contact"/></p> <p>Your email address: <span class="required">*</span></p> <p><input type="text" name="email" size="40" placeholder="Ex: example@xxx.com"/></p> <p>Website:</p> <p><input type="text" name="website" size="40" placeholder="Ex: http//:google.com"/></p> <p>Where you have heard us?: <span class="required">*</span></p> <p><select name="heard"> <option>Internet</option> <option>Newspapers</option> <option>Friends or relatives</option> <option>Others</option> </select></p> <p>Your message: <span class="required">*</span></p> <p><textarea cols="75" rows="20" name="message"></textarea></p> <p>Are you human? Sum this please: 5 + 7 = ?: <span class="required">*</span></p></p> <p><input type="text" name="captcha" size="10"/></p> <p><input type="submit" name="submit" value="Send" class="button"/> <input type="reset" value="Reset" class="button"/></p> </form> SECOND PROBLEM:If a user has made a mistake, he gets the error message so that he can correct! However, when a mistake in the form occurs, all the data the user has entered are disappeared! I want the data to keep appearing so that the user does not start over again to fill the form. THIRD: When the erro message is displayed to notify the user that he made a mistake when submitting the form, the message is displaying on the top of the page. I want it to appear below each respective field. How to do that? In JQuery it is simple, but in PHP, I am confusing! how can i disply this message withing the form echo "data submitted successfully!"; currently after validation check when data is entered the message show on top of my page not within the form function insertDATA($postData) { if(!ifEmailExists($postData['email'])){ $sql = " INSERT INTO tbl SET email = '".$postData['email']."', name = '".$postData['name']."', phone = '".$postData['phone']."' "; echo "data submitted successfully!";//this line withing the form executeSql($sql); } How do i display the image uploaded after the form has been submitted? After the form is submitted it will be a preview page, so i'm not storing the image type BLOB in MySQL yet. How do i display $_FILES['image']? Code: [Select] <?php if(isset($_POST['submit'])) { //preview page $info = getimagesize($_FILES['image']['tmp_name']); $imagetype = $info['mime']; $tmpname = $_FILES['image']['tmp_name']; $fp = fopen($tmpname,'r'); $data = fread($fp,filesize($tmpname)); $data = addslashes($data); fclose($fp); } else { ?> <form enctype="multipart/form-data" action="http://www.example.com/submit" method="POST"> <input type="file" name="image" value="" size="50" /> <input type="submit" name="submit" value="submit" /> </form> <?php } ?> Here I use two php page with two forms. my first form is 'sign_up.php' and second is select_subject.php'. sign_up.php page has more categories and users can select up to 3 more categories there. So. after selecting and user click the continue bottom, page want to go to second form page its select_subject.php page. If a user not select a category of who selected over 3 category I need to display a error message. like this "Please select atleast 1, not more than 3 categories." I use this HTML my first page Code: [Select] <form method="post" action="select_subject.php"> <my select boxes> </form> Then I process it in my second page and if user have made a mistake in first page I need to redirect to the first page again with relevant error message. So I use this code in my second page. Code: [Select] } else { // No valid ID, kill the script. $_SESSION['errors'] = "Please select atleast 1, not more than 3 categories."; $url = 'http://localhost/lanka_institute/tutorsignup/tutor_registration.php'; // Define the URL: ob_end_clean(); // Delete the buffer. header("Location: $url"); exit(); // Quit the script. } and my first page I use this Code: [Select] if (isset($_SESSION['errors'])) { echo '<p> ' . $_SESSION['errors'] . '</p>'; } unset($_SESSION['errors']); but it is not printing my error message in the first page that Im expecting. But it printing 'Array' instead of my message. can you help me, what is the mistake that I have done??? thanks in advance. Hi, I'm having a problem with contact form not display message log. It does successfully send, but fails to get the session variables. Where did I go wrong? This is my contact form code <?php include('includes/ui.php'); head('Contact Us','contactpage.css'); ?> <script src="js/SpryValidationTextField.js" type="text/javascript"></script> <link href="js/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <script src="js/SpryValidationTextarea.js" type="text/javascript"></script> <link href="js/SpryValidationTextarea.css" rel="stylesheet" type="text/css" /> <div class="section"> <h3>Contact Us</h3> <div class="scontent"> <?php /* ------------------------------------------------- Displays success/error message --------------------------------------------------*/ if ($_SESSION['message']!='') { ?> <div id="log"><?php echo $_SESSION['message']; ?></div> <?php unset($_SESSION['message']) ?> <?php } ?> <?php /* ------------------------------------------------- Contact Form --------------------------------------------------*/ ?> <p><em>If you have any questions, feel free to fill the form below:</em></p> <form action="sendmail.php" method="post"> <label>Name:</label> <span id="sprytextfield1"> <input type="text" class="istext" name="name"/> <span class="textfieldRequiredMsg">This field is required.</span></span> <label>Email:</label> <span id="sprytextfield2"> <input type="text" class="istext" name="email"/> <span class="textfieldRequiredMsg">This field is required.</span></span> <label>Message</label> <span id="sprytextarea1"> <textarea name="message"></textarea> <span class="textareaRequiredMsg">This field is required.</span></span><br/> </span> <label>Enter the code:</label> <img src="includes/captcha.php" /><span id="sprytextfield3"> <input class="input" type="text" name="norobot" /> <span class="textfieldRequiredMsg">This field is required.</span></span><br/> <input type="submit" class="btn" value="Send"/><span class="tab2em"></span><input type="reset" class="btn" value="Reset"/> </form> <div id="bible"> </div> <span class="clear"></span> <br class="clear"/> </div> </div> </div> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2"); var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); //--> </script> <?php footer(); ?> This is my sendmail.php <?php session_start(); if (md5($_POST['norobot']) == $_SESSION['randomnr2']) { // here you place code to be executed if the captcha test passes $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $name = filter_var($name, FILTER_SANITIZE_STRING); $email = filter_var($email, FILTER_SANITIZE_EMAIL); $message = filter_var($message, FILTER_SANITIZE_STRING); require_once('includes/class.phpmailer.php'); $mail = new PHPMailer(); $body = "Someone with the ".$name." and an email address of ".$email." send you the ff message: ".$message; $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "mail.example.com"; // SMTP server $mail->SMTPAuth = true; // enable SMTP authentication $mail->Host = "mail.example.com"; // sets the SMTP server $mail->Port = 26; // set the SMTP port for the GMAIL server $mail->Username = "example@example.com"; // SMTP account username $mail->Password = "thepassword"; // SMTP account password $mail->SetFrom('example@example.com', 'Me'); $mail->Subject = "Message sent from site contact form"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($body); $address = "tosomeone@yahoo.com"; $mail->AddAddress($address, "Richard"); if(!$mail->Send()) { $_SESSION['message'] = "Failed sending, please try again later"; } else { $_SESSION['message'] = "Message sent"; } } else { // here you place code to be executed if the captcha test fails $_SESSION['message'] = "Invalid code"; } header('Location: http://example.com'); ?> Thanks in advance Hi there, New to the forum... thank you in advance for any help! I created a login system using a tutorial found online. Everything works perfectly.. but now the client wants "Hello [First Name]" displayed after logging in. I've tried about 12 different tutorials at this point and can't seem to tweak them enough to work with my code. A lot of the tutorials have session_start(); at the top of their protected (welcome.php) page. But mine seems to be held in a variable in another script and the top of my welcome.php looks like this: Code: [Select] <?PHP require_once("./include/membersite_config.php"); if(!$fgmembersite->CheckLogin()) { $fgmembersite->RedirectToURL("login.php"); exit; } ?> This is what I have on my welcome page as well but I don't know how to make this all come together and work.. Code: [Select] Hello <?php echo $_SESSION['name']; ?> I'm using mySQL 5.0, and php 5.2. Will anyone shed light on this for me? I'll provide any other info you may need.. Thank you I am trying to display "open" / "closed" depending on the time of day. I tried to write my own script but it doesn't seem to be working. Does anyone know of some boxed script I can use? Here is what I have... function open(){ $AMPM = date('A', time()); if ($AMPM == "PM"){ connect(); $day = date('l'); $sqlcurrent = "select * from hours where day = '$day' and closed ='1'"; $currently = mysql_query($sqlcurrent) or die(mysql_error()); $checkDay = mysql_num_rows($currently); if ($checkDay == "1"){ while($getID = mysql_fetch_assoc($currently)){ $convertopen = strtotime($getID['open']); $convertclose = strtotime($getID['close']); $displayTimeH = date('H', time()); $displayTimeM = date('i', time()); $displayTimeAMPM = date('A', time()); $opentime = explode(":", $getID['open']); $openhour=$opentime[0]; $openminute=$opentime[1]; $closetime = explode(":", $getID['close']); $closehour=$closetime[0]; $closeminute=$closetime[1]; //echo "$closehour$closeminute<br />"; //echo "$displayTimeH$displayTimeM<br />"; if (($openhour <= $displayTimeH && $openminute <= $displayTimeM) && ($closehour >= $displayTimeH && $closeminute >= $displayTimeM)){ echo "We're Open ... Come On In!"; }else{ echo "Hours of Service"; } } }else{ echo "Hours of Service"; free($currently); } }else{ echo "Hours of Service"; } } // close function I know it's brutal but it's all I could come up with... I have a login modal window which is user for entering the login and password, and check it with the database.If the login and password is not there i nthe database the message shuld be displayed in the popup window itself. But in my case the popup window disapperas if the login details are wrong. how shuld i code for this. My code is pasted below. <div id="cover"></div> <div id="dialog"> <form action='' method='post' name='onlinepay'> <table width="388" border=1><tr><td colspan="4" align="right"></td><td align="right"><a href="index.php" onclick="closePopUp('dialog');"><img src='images/close.jpg' align="right" /></a></td></tr> <tr><td width="11" ></td> <td width="90">Username </td> <td width="57">:</td> <td width="147"><input type='text' name='username' id='username' /></td><td width="59"></td> </tr> <tr><td></td><td>Password</td><td>:</td><td><input type='text' name='password' id='password' /></td><td><input type='submit' name='submit' id='submit' value="Login" /></td></tr><tr><td colspan='5'><?php //connection statements goes here if(isset($_POST['submit'])){ $username=$_POST['username']; $password=$_POST['password']; $sql="select username,password from register where username='$username' and password='$password'"; $result=mysql_query($sql); $row=mysql_fetch_row($result); $row1=mysql_num_rows($result); if(($row['0']==$username) && ($row['1']==$password)){ header ('Location:themes/index.php'); } else{ echo "Username and password doesnot match"; } } ?> </td></tr> <tr><td colspan="5"><hr color="#999999" /></td></tr><tr><td></td><td colspan='2'><a href="javascript:void window.open('themes/forgotpassword.php?fullview=Y','','height=350,width=525,resizable=yes,scrollbars=yes')">Forgot password? </a> </td> <td><a href='register.php'>New User</a></td> <td align='center'> </td> </tr> </table> </form> Hi,
I'm trying to display a message first before redirect to other page, but my code just directly redirect the page without display the message.please help me.
if($num_rows == 0) { echo '<script type="text/javascript">alert("Please Enter Correct Details!");</script>'; header ('Location :login.php'); } Say I have an "Entries" table. I want to submit same multiple entries using a form submission. And If I have other queries submitted in the same form, I want those quarries to be submitted only once. Is that possible to do? Here's my code. if(isset($_POST['submit'])) { $entries = 10; $id = 55; $name = 'Smith'; $insert = $db->prepare("INSERT INTO entries(id, name) VALUES(:id, :name)"); $insert->bindParam(':id', $id); $insert->bindParam(':name', $name); $result_insert = $insert->execute(); if($result_insert == false) { echo 'Fail'; } else { echo 'Success'; } } ?> <form action="" method="post"> <input type="submit" name="submit" value="SUBMIT" /> </form> Edited January 13, 2019 by imgrooot Hello all, my first post after joining this very informative site, unfortunatly I was unable to find the answer to my simple yet frastrating dilemma. I am in the process of building a website that will enable users to log-in through a dedicated loginU.php page, I have all of this working but I would like to display an error message on this page saying if the user has entered a wrong username/password, I have the message displaying on a blank white page, but I would like it to be displayed within the container I have created. the validation code is contained within a different login.php file. At the moment I am using an iframe to display the messages, which I know is not the right way to do it, so am asking for a better way to do it. here is what I have so far: loginU.php Code: [Select] <div id = "div-Login"> <form action="login.php" method="POST" target="loginerror"> <center><h2>Login Here</h2> <p> Username: <input type="text" name="username"><p> Password: <input type="password" name="password"><p> <input type="submit" name="submit" value="Login"> </center> <a href="register.html"><pre>need to register? Click Here!</pre></a> </form> <iframe name="loginerror" style="border: 0px; width: 200px; height: 100px; overflow: hidden;" src="login.php"></iframe> </div> login.php Code: [Select] if ($username==$dbusername&&$enc_password==$dbpassword) //if the username & encrpyted password matches the records in the database { if($admin !=0) //if the admin flag is true { $_SESSION['level']='ADMIN';//admin is logging in header ("Location: admin.php"); //the user is an admin, direct to admin page } else header ("Location: index.php"); //user is a customer, direct user to index page $_SESSION['username']=$dbusername; //set the session name to the database record username. } else //$nopass='TRUE'; //header ("location: loginU.php"); echo "Incorrect Password, Please try again"; // if incorrect password } else die ("That username doesn't exist"); // if user doesn't exist } else die ("Please enter a username and password"); //if either field is empty ?> Hi. Pretty straight forward I guess but as the name suggests am a newbie. I have a form that requires the user to enter certain parameters. If the values are blank it submits to itself and loads the error messages. What I want to do is create PHP code that submits the form to a different url. What I thought was create two forms (the second with hidden fields replicating the first form), each form having a different url in the action"" code. What I cant work out is the PHP IF ELSE code to submit form 2 if Form1 is is validated correctly. This is the PHP code relevant to the form validation. Help? <?php //If form was submitted if ($_POST['submitted']==1) { $errormsg = ""; //Initialize errors if ($_POST[width]){ $title = $_POST[width]; //If title was entered } else{ $errormsg = "Please enter width"; } if ($_POST[drop]){ $textentry = $_POST[drop]; //If comment was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . " & content"; }else{ $errormsg = "Please enter drop"; } } } if ($errormsg){ //If any errors display them echo "<div class=\"box red\">$errormsg</div>"; } //If all fields present if ($title && $textentry){ //Do something echo 'THIS IS WHERE I WANT THE CODE TO SUBMIT FORM 2 or SUBMIT FORM 1 TO A DIFFERENT URL'; } ?> Please i need help on popup message when an image is clicked. Some one should help me with the code to place in my html document. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347166.0 If my form is submitted, but fails during PHP validation, then I want info that was already submitted to be available. <input type="text" name="username" value="<?php if(isset($_POST['username'];} { echo $username; } ?> > </div> This works fine and defines my goal. My troubles arose when I attempted a similar design with a drop-down menu. Making matters worse, that menu uses JavaScript. <script> document.write("<select name='menu'>"); for(i = 1; i < 20; i++) { document.write("<option value=' "+i+"'> " + i + "</options>"); } document.write("</select>"); </script> I've begun trying to add PHP into the <option> tag, but am not sure how (or if it's acceptable) to integrate the JS for the desired result. document.write("<option value=' "+i+"' <? if($_POST['menu'] == ?> +i+ <? echo selected";?> > " + i + "</options>"); I suppose I could swap the JS with PHP, but then I put unnecessary usage to the server. Best solution?? As some of y'all may not know, I am new to this php coding stuff so if anything does not work the way I want it to, it goes to the forum. And this is the case when just after I solved a problem with my first contact form, I run into another problem again. My latest problem involves the form error thing that tells you that you did not enter any required fields. After I added a error message thing to my contact page and tested it, it doesn't show up. Oh and here's the code: Code: [Select] <?php if ($missing || $errors) { ?> <div id="maincontent"> <p class="warning">You did not enter the required information. Please try again.</p></div> Here is what makes up my contact form. Code: [Select] <?php $errors = array(); $missing = array(); if (isset($_POST['send'])) { $to = 'tate.mikey@gmail.com'; $subject = 'New Feedback Received on MikeyTateLive Productions website'; $expected = array('name', 'email', 'comments'); $required = array('name', 'comments'); require ('/www/zymichost.com/m/t/l/mtlproductions/htdocs/processmail.inc.php'); } ?> <div id="wrapper"> <div id="maincontent"> <p>*=required</p> </div> </div> <form id="feedback" method="get" action=""> <p> <label for="name">*Name:</label></br> <input name="name" id="name" type="text" class="formbox"> </p> <p> <label for="email">Email:</label></br> <input name="email" id="email" type="text" class="formbox"> </p> <p> <label for="comments">*Comments:</label></br> <textarea name="comments" id="comments" cols="60" rows="8"></textarea> </p> <p> <input name="send" id="send" type="submit" value="Send" </p> </form> Form.php Code: [Select] <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="registration.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Set Name' class='biasa' ></form> <br> <br> </body> </html> Registration.php Code: [Select] <?php $m=$_POST['message']; echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('$m')</SCRIPT>"); ?> <html> <head> <script type="text/javascript"> function a() { var x = document.register.username.value; var y = document.register.pass.value; var z = document.register.pass2.value; if(x==""&& y==""&& z=="") { alert("Please insert all message!"); return false; } if(x=="") { alert("Please insert an username!"); return false; } if(y=="") { alert("Please insert an password!"); return false; } if(z=="") { alert("Please insert an password2!"); return false; } if (y!=z) { alert("Your passwords did not match"); return false; } } </script> </head> <body> <form name="register" method="post" action="login.php" onsubmit="return a()"> <table border='0'> <input type="text" name="<?php $m?>"> <tr><td>Username:</td><td><input type="text"name="username" maxlength="60"></td></tr> <tr><td>Password:</td><td><input type="password" name="pass" maxlength="10"></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="pass2" maxlength="10"></td></tr> <tr><th colspan=2><input type="submit" name="sub" value="Register"></th></tr> </table> </form> </body> </html> Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> This i took from form.php and when it passed to registration.php when im called it in javascript <?php $m=$_POST['message']; echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('$m')</SCRIPT>"); it can show the message im put in form.php but when im put into input text that is <input type="text" name="<?php $m?>"> but the input text is blank not put the message im post in form php may i know which is the error Hello, first time poster.. I've looked the web over for a long time and can't figure this one out. - Below is basic code that successfully checks MySQL for a match and displays result. I was debugging and forced the "height" and "width" to be 24 and 36 to make sure that wasn't the problem. That's good.. - I'd like to give the user ability to select width and height from a form.. and have it do an onchange this.form.submit so the form can be changing as fields are altered (thus the onchange interaction) - In a normal coding environment I've done this numerous times with no "Page cannot be displayed" problems. It would simply change one select-option value at a time til they get down the form and click submit... but in WordPress I'm having trouble making even ONE single onchange work! - I've implemented the plugins they offer which allows you to "copy+paste" your php code directly into their wysiwyg editor. That works with basic tests like my first bullet point above. - I've copied and pasted the wordpress url (including the little ?page_id=123) into the form "action" url... that didn't work... tried forcing it into an <option value=""> tag.. didn't work. I'm just not sure. I've obviously put xx's in place of private info.. Why does this form give me Page Cannot Be Displayed in WordPress every time? It won't do anything no matter how simple.. using onchange.. Code.. $con = mysql_connect("xxxx.xxxxxxx.com","xxxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxx", $con); $myprodwidth=24; $myprodheight=36; $result = mysql_query("SELECT * FROM product_sizes WHERE prodwidth='$myprodwidth' and prodheight='$myprodheight'"); while($row = mysql_fetch_array($result)) { echo $row['prodprice']; } mysql_close($con); <form method="post" action=""> <select name="myheight" onchange="this.form.submit();"> <option selected="selected" value="">select height</option> <option value="xxxxxxxxx.com/wordpress/?page_id=199&height=36">36</option> <option value="xxxxxxxxx.com/wordpress/?page_id=199&height=36">48</option> </select> Hi I built a really simple customer review form https://kickasssoftwear.uk/dev/reviews.html (it's only been optimised for mobile view so far) and it works using the php mail script on this page https://kickasssoftwear.uk/dev/empty2.php - the emails are being sent to me and the format of the emails is OK, and the form redirects to the empty2 page with a mailsent message in the address bar. I know I can leave that page as is and write a nice thank you message in the html - but what I really want to do is have the customers name there too, Thanks 'name' your review has been sent, but I can't get it to work - it's been 4 whole days now and I really need to eat & sleep! Please if anyone has suggestions or advice for a noob, please help. Thanks Hi, having problems getting checkboxes to display all reuslts when a user selects more than one check box say in the category section and one in the location section - see page http://www.partyco.co.uk/event-and-party-venues/ - submit to see reults page: I managed to get it to display reults if the user only seletc either a right or left column option OR one of each - BUT not when thet select multiple categories and one location - and ideas how to do this ? putting it into an array perhaps - but how - new to some of this.... here is the code for the reults page: Code: [Select] <?php $location = $_POST[location]; $category = $_POST[category]; ?> <?php $Link = mysql_connect("xxxxxxxxx", "xxxxxxxxx", "xxxxxxxx") or die(mysql_error()); mysql_select_db("xxxxxxxx") or die(mysql_error()); // selects db listings when location not given if (empty($location)) { $query = "SELECT * FROM venues WHERE category = '$category' order by title"; $result = mysql_query($query) or die(mysql_error()); // selects db listings when category not given } elseif(empty($category)) { $query = "SELECT * FROM venues WHERE location = '$location' order by title"; $result = mysql_query($query) or die(mysql_error()); // selects db listings when both given }else { $query = "SELECT * FROM venues WHERE category = '$category' and location = '$location' order by title"; $result = mysql_query($query) or die(mysql_error()); } while($row = mysql_fetch_array($result)){ echo "<div class=\"resultsShort\" style=\"margin-bottom:10px;\">"; echo "<h2 id=\"resultsHeading\">"; echo $row['title']; echo "</h2>"; echo "<p class\"resultspara\">". nl2br($row['description']). "</p>"; echo "<h4 style=\"margin:5px 0 0 0; padding:0;\">Contact details</h4>"; echo "<p class\"resultspara\">". nl2br($row['contact']). "</p>"; echo "<div style=\"float:left; width:124px; height:40px; margin:10px 15px 0 0;\">"; echo "<a href=\"/party-supplier-resources/email-supplier.php?title=". $row['title']. "&email=" . $row['email']. "&location=" . $row['location']. "&category=" . $row['category']. "\" title=\"contact this venue here\">"; echo "<img src=\"/images/email-supplier.jpg\" width=\"124\" align=\"right\" height=\"35\" alt=\"contact this supplier button\" border=\"0\" /></a>"; echo "</div>"; echo "</div>"; } ?> <?php include("../include/shareLinks.php"); ?> <div id="popupContact"> <a id="popupContactClose" title="close this window">close x</a> <h1>Supplier Directory Enquiry Form</h1> <?php include("../include/enquiryform.php"); ?> </div> <div id="backgroundPopup"></div> <?php mysql_close ($Link); ?> Any help appreciated! Aaron MOD EDIT: [code] . . . [/code] BBCode tags added. |