PHP - Keep User Input In Form After A Submit
hello all, i have a php form with multiple submits (one calculates price, one checks date and one submits the form and the data to mysql database)
when i hit calculate price, for example, the function works fine but all the fields are cleared and i would like for all the input to remain as the user sent. here is part of the code (the form): Code: [Select] <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <fieldset> <legend ><span><a>video</span></a></legend> <ol> <li> <label for="hover_camera">hover camera</label> <input id="hover_camera" type="radio" name="hover_camera" value="yes" /><b>yes</b> <input id="hover_camera" type="radio" name="hover_camera" value="no" /><b>no</b> </li> <li> <label for="video_photographers">video photographers</label> <input id="video_photographers" type="text" name="video_photographers" maxlength="1" size="1"/> </li> <li> <label for="video_edit">video edit</label> <input id="video_edit" type="radio" name="video_edit" value="short" /><b>short</b> <input id="video_edit" type="radio" name="video_edit" value="long" /><b>long</b> </li> <li> <label for="video_clip">video clip</label> <select name="video_clip"> <option value="no">no</option> <option value="regular">regular</option> <option value="staged">staged</option> </select> </li> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>stills</span></a></legend> <ol> <li> <label for="stills">stills</label> <input id="stills" type="text" name="stills" maxlength="1" size="1" /> </li> <li> <label for="increase">increase amount</label> <input id="increase" type="text" name="increase" maxlength="4" size="1" /> </li> <li> <label for="magnets">magnets</label> <input id="magnets" type="text" name="magnets" maxlength="4" size="1" /> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>albums</span></a></legend> <ol> <li> <label for="digital_album">digital album</label> <input id="digital_album" type="radio" name="digital_album" value="yes" /><b>yes</b> <input id="digital_album" type="radio" name="digital_album" value="no" /><b>no</b> </li> <li> <label for="photo_album">photo album</label> <input id="photo_album" type="radio" name="photo_album" value="yes" /><b>yes</b> <input id="photo_album" type="radio" name="photo_album" value="no" /><b>no</b> </li> <li> <label for="small_digital_album">small digital album</label> <input id="small_digital_album" type="radio" name="small_digital_album" value="yes" /><b>yes</b> <input id="small_digital_album" type="radio" name="small_digital_album" value="no" /><b>no</b> </li> </ol> </fieldset><br /> <fieldset align="right"> <ol> <li> <label for="comments">comments</label> <textarea id="comments" name="comments"></textarea><br /><br /> </li> <li> <label for="price">price</label> <td><input type="submit" id = "price" name="price" value="calculate price" /></td> </li> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>choose date</span></a></legend> <ol> <li> <input type="submit" id="isavailable" name="isavailable" value="isavailable" /> </li> </ol> </fieldset> <fieldset class="submit"> <ol> <li> <input class="submit" type="submit" id="submit" name="submit" value="done!" /> <input class="submit" type="reset" id="reset" name="reset" value="reset" /> </li> </ol> </fieldset> </form> thanks for the help Similar TutorialsHello everyone, I want my input to stay after I have clicked submit so that if the input is wrong, a message is presented and the input stays so they don't have to write everything again. Is this the way to do it?: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head xmlns='http://www.w3.org/1999/xhtml'> <title>registration</title> <link rel="stylesheet" type="text/css" href="opmaak.css" /> </head> <body> <?php function __autoload($class){ require('classes/' . strtolower($class) . '.class.php'); } if ($_SERVER['REQUEST_METHOD'] == 'POST'){ if(isset($_POST['firstname'])){ $firstname = $_POST['firstname']; } if(isset($_POST['lastname'])){ $lastname = $_POST['lastname']; } if(isset($_POST['address'])){ $address = $_POST['address']; } if(isset($_POST['postcode'])){ $postcode = $_POST['postcode']; } if(isset($_POST['city'])){ $city = $_POST['city']; } if(isset($_POST['username'])){ $username = $_POST['username']; } if(isset($_POST['password'])){ $password = $_POST['password']; } if(isset($_POST['email'])){ $email = $_POST['email']; } if(isset($_POST['kvk'])){ $kvk = $_POST['kvk']; } try{ $user = new User; $user->createUser($firstname, $lastname, $address, $postcode, $city, $username, $password, $email, $kvk); } catch(Mysql_Exception $error){ echo $error->getError(); } echo "<html>"; echo "<head xmlns='http://www.w3.org/1999/xhtml'>"; echo "<title>registration</title>"; echo "<link rel='stylesheet' type='text/css' href='opmaak.css' />"; echo "</head>"; echo "<body>"; echo "<div id='registration_container'>"; echo "<form class='registration' method='post' action='registration.php'>"; echo "<div id='registration_left'>"; echo "<label class='user'>Voornaam: *</label> <input class='registration' type='text' size='10' maxlength='40' name='firstname' value='".$firstname."'/>"; echo "<label class='user'>Achternaam: *</label> <input class='registration' type='text' size='10' maxlength='40' name='lastname' value='".$lastname."'/>"; echo "<label class='user'>Adres: *</label> <input class='registration' type='text' size='10' maxlength='40' name='address' value='".$address."'/>"; echo "<label class='user_postcode_plaats'>Postcode / Plaats: *</label> <input class='registration_postcode' type='text' size='10' maxlength='40' name='postcode' value='".$postcode."'/>"; echo " "; echo "<input class='registration_city' type='text' size='10' maxlength='40' name='city' value='".$city."'/>"; echo "</div>"; echo "<div id='registration_right'>"; echo "<label class='user'>Gebruikersnaam: *</label> <span class='inputeisen'>4 of meer</span><input class='registration' type='text' size='10' maxlength='40' name='username' value='".$username."'/>"; echo "<label class='user'>Wachtwoord: *</label> <span class='inputeisen'>6 of meer</span><input class='registration' type='text' size='10' maxlength='40' name='password' value='".$password."'/>"; echo "<label class='user'>E-mail: *</label> <input class='registration' type='text' size='10' maxlength='40' name='email' value='".$email."'/>"; echo "<label class='user'>KvK nummer:</label> <input class='registration' type='text' size='10' maxlength='40' name='kvk' value='".$kvk."'/>"; echo "</div>"; echo "<div id='registration_bottom'>"; echo "<p>Het KvK nummer is alleen verplicht indien u wilt adverteren met uw bedrijf.<br/> U kunt dit ook later toevoegen.</p>"; echo "<input class='submit_registration_user' type='submit' value='Registreren'/>"; echo "</div>"; echo "</form>"; echo "</div>"; echo "</body>"; echo "</html>"; }else{ ?> <div id="registration_container"> <form class="registration" method="post" action="registration.php"> <div id="registration_left"> <label class="user">Voornaam: *</label> <input class="registration" type="text" size="10" maxlength="40" name="firstname"/> <label class="user">Achternaam: *</label> <input class="registration" type="text" size="10" maxlength="40" name="lastname"/> <label class="user">Adres: *</label> <input class="registration" type="text" size="10" maxlength="40" name="address"/> <label class="user_postcode_plaats">Postcode / Plaats: *</label> <input class="registration_postcode" type="text" size="10" maxlength="40" name="postcode"/> <input class="registration_city" type="text" size="10" maxlength="40" name="city"/> </div> <div id="registration_right"> <label class="user">Gebruikersnaam: *</label><span class="inputeisen">4 of meer</span> <input class="registration" type="text" size="10" maxlength="40" name="username"/> <label class="user">Wachtwoord: *</label><span class="inputeisen">6 of meer</span> <input class="registration" type="text" size="10" maxlength="40" name="password"/> <label class="user">E-mail: *</label> <input class="registration" type="text" size="10" maxlength="40" name="email"/> <label class="user">KvK nummer:</label> <input class="registration" type="text" size="10" maxlength="40" name="kvk"/> </div> <div id="registration_bottom"> <p>Het KvK nummer is alleen verplicht indien u wilt adverteren met uw bedrijf.<br/> U kunt dit ook later toevoegen.</p> <input class="submit_registration_user" type="submit" value="Registreren"/> </div> </form> </div> </body> </html> <?php } ?> Hi there, I found a Javascript with what I want, but I want it to be in PHP because if people don't have Javascript enabled, they won't see the login. Here is what I have, but I need it to be converted to PHP: Code: [Select] function loginArea() { val = document.loginForm.password.value; switch(val) { case "password1": document.location = 'http://www.google.com/password1-page/'; break; case "password2": document.location = 'http://www.google.com/password2-page/'; break; default: document.location ='http://www.google.com/sorry/'; break; } } Code: [Select] <form name="loginForm" id="loginForm" method="post" action=""> <input name="password" type="text" id="password" maxlength="5" /> <input name="login" type="button" id="login" value="Check" onclick="loginArea()" /> </form> Help? - Steph I was wondering just a general question here. I am just going through a text book on the main aspects of a problem solving approach to PHP, but when I was just trying out one of my own theories on this particular one of my own: <html> <body> <h1>User Input set as functions</h1> <tt>Please enter a value below:</tt> <br> <form id="userInput" name="userInput" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get"> <input type="text" id="input" name="input" value="" /> <input type="submit" value="Send This" /> </form> <?php function mistake($errorvalue) { echo $errorvalue; } function getValue($userInput) { return $userInput; } if(!isset($_GET['input']) || $_GET['input'] == '') { mistake("No value received yet!"); // calls the error function } else { $input = $_GET['input']; echo "You did enter something, this was: "; $userInput = getValue($input); echo "$userInput"; } ?> </body> </html> I am quite impressed with what I have done there, though I know its nothing special and could obviously be done not using functions at all, just wanted to see if I could get one that returns something, in this case the 'getValue()' function. But when I've set it to work out what type of variable ie gettype is it? (going off completely memory here), its always a string, even if all I do is enter a 1, even tried not using the GET method for the form and used the POST one instead it still says that a single integer is a string. Why just out of question is it doing this? Just quite interested thats all. Thanks for your time and I look forward to any replies, Jeremy. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=319994.0 Im trying to make my form remember the last input made by user, so I wrote the following and I get a syntax error on the input line. The error is: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\ezsynonym\index.php on line 90 Code: [Select] <form id="searchform" method="post" action="index.php"> <input id="input" name="synonymsearch" type="text" value="<?php echo $_POST['synonymsearch']; ?>" maxlength="400px" /> </form> TIA The PHP code sends me an email from the server, but the user input is empty or "blank". I only receive: "From: \ Email: \ Subject: \ Message: " and that's it. How do I fix my PHP and/or HTML code to receive user input from the form? Attached is my existing HTML and PHP code that doesn't send me any "user input" from the form. Thanks to anyone who can help!!
Say there is a complex opt in process where people start to enter their data but certain questions stop them where they close out of the page. They already entered their data and I feel there is a way to grab it and post it to mysql even though they do not click submit.
How would this be done?
A super simple example (proof of concept) or a link to a tutorial would be very useful.
Edited by brentman, 23 September 2014 - 10:42 AM. 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 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'; } ?> Hey guys! I'm pretty new to php and starting work on a project, the first part I'm working on is a html page with text fields like this: Quote URL: Dropdown box: Submit when the submit happens I want it to post to a php page, parse whatever is inside a set of <h2> tags and print it to to the php page, also the user selects four options from the dropdown box and I need to print the string contained in the selection to the next page as well, As I said I'm pretty new but here's what i threw together so far based on references I found, but it doesn't work correctly: parse.html: Code: [Select] <html> <body> <form action="parse.php" method="post"> URL: <input type="text" name="turl" /> <br> Option: <select name="selectskill"> <option value="1">Low</option> <option value="2">Mid</option> <option value="3">High</option> <option value="4">Known</option> </select> <br> <br> <input type="submit" /> </form> </body> </html> parse.php: Code: [Select] <html> <head></head> <body> <?php $lol = $_POST["turl"]; $str = file_get_contents($lol); $DOM = new DOMDocument; $DOM->loadHTML($str); // Grab text inside the heading 2 tags $items = $DOM->getElementsByTagName('h2'); echo "option: " . $lol; // Display the content inside the second set of H2 tags echo $items->item(1)->nodeValue . "<br/>"; ?> </body> </head> </html> Thanks for all the help in advance! OK so i have a textfield and i have everything going to the database and then displaying on the page. Now is there a way to display code on the page but disable it from executing? There are some break tags in there so i would still like them to be executed on the page. Hello, Firstly I am only just learning php so please bear with me. What I want to be able to do is for a user to be able to enter a youtube url eg: Code: [Select] http://www.youtube.com/watch?v=8xz7ShMCWls I want the scrip to take the video ID (after watch?v=) and append it into a html embed code for our forums that do not have the feature to auto embed a youtube vid. Code: [Select] <p> <img height="350" width="425" class="fw_media_youtube fw-parse" alt="YouTube-AFTER WATCH?V=CODE" src="http://thumbs.webs.com/Platform/mediaPreview.jsp?type=YouTube&id=AFTER WATCH?V=CODE"/></p> Where you see AFTER WATCH?V=CODE is where I want it to place the video id and then return this completed code for the user to copy and paste: Code: [Select] <p> <img height="350" width="425" class="fw_media_youtube fw-parse" alt="YouTube-8xz7ShMCWls" src="http://thumbs.webs.com/Platform/mediaPreview.jsp?type=YouTube&id=8xz7ShMCWls"/></p> How would I be able to get this done. I do not expect to be spoon fed but just a litlle help please. Thank you so much if you do help. Hi, I'm using the form data type 'date', and trying to verify it. It seems a little too complicated to check that it's in the correct format (with "/" between day/month/year), unless I use regular expression, which I don't know much about and seems feels like there's an alternate solution or it's not necessary. Currently, the script accepts DD*MM*YYYY, where * is any character, since it just strips the 3rd and 6th character and checks the day/month/year using checkdate(). I'm not even sure if this is a problem. I am giving the user a "verify" page, where I could put it in the correct format (DD/MM/YYYY), but is that enough? Feel like I'm missing something here, so any feedback would be great I appreciate your help guys. I was able to do something to the code. Now it looks like this: <?php include "include/dbc.php"; include "include/header.inc"; ?> <script type="text/javascript"> <!--Hide Code // Function Statements //Function to confirm submit function confirmSubmit() { var submitform = window.confirm("Are you sure you want to submit the activities?"); if (submitform == true) return validateForm(); return false; } // End Hide--> </script> <style type="text/css"> .mydate{ color:#00F; text-decoration:underline; cursor:pointer; } </style> <script type="text/javascript"> function displayDate(d){ var date=new Date(); var D=date.getDate(); date.setDate(D+d); var YYYY=date.getFullYear(); var MM=date.getMonth()+1; MM<10?MM='0'+MM:null; var DD=date.getDate(); DD<10?DD='0'+DD:null; var span=document.getElementById('date'); span.innerHTML= 'Entries for '+MM+'/'+DD+'/'+YYYY; } onload=function(){displayDate(0)}; </script> <h1>Food Diary</h1> <div class="full"> <center><div><span class="mydate" onclick="displayDate(-1)"><img src="images/left_arrow.png" border="0">Yesterday</span> <span id="date" style="font-size:2em;"></span> <span class="mydate" onclick="displayDate(1)">Tomorrow<img src="images/right_arrow.png" border="0"></span></div><br /> <a href="#" onclick="displayDate(0);return false;">Today</a> </center> <div class="full"> <form name="exercise" id="exercise" method="GET" action=""> <center><table> <tr> <td><h3>Add an Activity</h3></td> </tr> <tr> <td><input name="NewSearchString" style="width: 100px" type="text"/> <input type="submit" value="Search" /> </td> </tr> <tr> <td> <select name="activity"> <option value="_">Activity Browse...</option> <option value="all">All Activities</option> <option value="biking">Biking</option> <option value="condition">Conditioning</option> <option value="dancing">Dancing</option> <option value="fish">Fishing & Hunting</option> <option value="Home">Home Activities</option> <option value="misc">Miscellaneous</option> <option value="music">Music Playing</option> <option value="occupation">Occupation</option> <option value="running">Running</option> <option value="sports">Sports</option> <option value="walking">Walking</option> <option value="water">Water Activities</option> <option value="winter">Winter Activities</option> </select> <input type="submit" value="Submit" /></td></tr></table></center></form> </td> </tr> </table> </center> <table width="100%"> <tr bgcolor="#66CC33"> <td><div>Activity</div></td> <td><div>Specific Activity</div></td> <td><div>Time (hh:mm)</div></td> <td><div>Distance</div></td> <td><div>Units</div></td> </tr> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr> <?php if(isset($_GET[activity])) { $category=$_GET[activity]; $result = mysql_query("SELECT * FROM exercise WHERE type='$category'"); ?> <form action="add_activity.php" method="POST"> <?php while($row = mysql_fetch_array($result)) { echo '<tr><td><div>'.$row[Type].'</div></td>'; echo '<td><div>'.$row[Name].'<input type="hidden" name="exerciseid" value="'.$row[Name].'"></div></td>'; echo '<td><div><input type="text" name="duration['.$row['Name'].']"></div></td>'; echo '<td><div><input type="text" name="distance['.$row['Name'].']"></div></td>'; echo '<td><div><select> <option value="mile" name="mile">mile</option> <option value="Km" name="Km">km</option> <option value="M" name="M">m</option> <option value="Yard" name="yard">yrd</option> <option value="Feet" name="feet">ft</option> </select></div></td></tr>'; } mysql_close(); ?> <tr><td colspan="6" align="center"><input type="submit" name="submit" value="Add Activities"></td></tr> </form> <?php } ?> <tr bgcolor="#66CC33"> <td><div></div></td> <td><div></div></td> <td><div></div></td> <td><div class="Float"></div></td> <td class="cp_Distance"><div></div></td> </tr></table> This somewhat works. The problem is that this code passes all the activities to the second page, where the output looks like this: Array ( [exerciseid] => Hunting, general [duration] => Array ( [Fishing from boat, sitting] => 20 [Fishing from river bank, standing] => [Fishing in stream, in waders] => [Fishing, general] => [Fishing, ice, sitting] => [Hunting, general] => ) [distance] => Array ( [Fishing from boat, sitting] => 25 [Fishing from river bank, standing] => [Fishing in stream, in waders] => [Fishing, general] => [Fishing, ice, sitting] => [Hunting, general] => ) [submit] => Add Activities ) Is there a way I can pass what the user input instead of passing everything (form validation maybe?) Hi, what is they best way to validate user input of strings? A couple of examples would be : 1> If i wanted to check for the existance on the coma ',' character in a string and replace it with a dash '-' character? 2> To check wether a user has entered a valid ip address in the form of x.x.x.x where x can range from 0-255? I think i may need ereg/preg to do this but i have no idea about how to layout the syntax. Thanks for looking. Well this may sound confusing. I tried to findways to allow users to input an integer value and then assign it to a variable called $quantity, but all I could find from the internet was the usage of forms. Do I have to use forms, or can I just try this this simple syntax: $quantity = "<input name='quantity' type='text' id='quantity' size='3' maxlength='3'>"; If I do have to use forms, then how can I ever assign user's input value to a variable? Please help. I manage a simple website for a small business - nothin fancy. I'm interested using some php to enhance the site a bit. I'm looking to accept some user input and put it into a database then display it back to them on another page. What php functions would be best to use to accomplish this? Thanks for the input! Ok so I got BB Code working. Now I want to prevent Users from inserting HTML into Posts. I have the following: $PostText = mysql_escape_string($_POST['replytext']); $Replace = Array ('/(<)(.+)(>)/','/(<\/)(.+)(>)/'); $ReplaceWith = Array ('<\\2>','</\\2>'); $PostText = preg_replace($Replace, $ReplaceWith, $PostText); Now If I were to input Code: [Select] <a href=http://phpfreaks.net>Php Freaks</a>Into a forum reply it would return: Code: [Select] <a href=http://phpfreaks.net>Php Freaks When Checking the database it has: Code: [Select] <a href=http://phpfreaks.net>Php Freaks</a> Any help on solving this? Hello, I'm creating an application where a user can input there own CSS. The problem I'm having is understanding if this will open security holes if... 1. Users input is saved to a file called style.css 2. Each user is on their own a sub-domain from my reseller hosting plan. 3. The style.css file will be included in the page code like so: Code: [Select] <link type='text/css' rel='stylesheet' href='style.css' /> Any advice? |