Jump to content

Search the Community

Showing results for tags 'form'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • RuneLocus
    • News & Announcements
    • Information Booth
    • Website Support
    • Introductions
    • Chat
    • Forum Games
  • RuneScape Development
    • RSPS General
    • RuneScape Private Server (RS2)
    • RuneScape Private Server (503+)
    • RuneScape Private Server (EoC 742+)
  • Other
    • Digital Art
    • Gaming
    • Webdevelopment
    • Computers
  • Marketplace
    • RuneScape Market
    • RSPS Market
    • Others Market
    • Freelance Middleman Services
  • Super Secret Club's Topics

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 5 results

  1. Hello Runelocus users, [B]Update: Code is updated, now the method (POST,GET,PUT,DELETE) gets retrieven from the form tag too, so you can now easily use this single code snippet for any form if you remove '#' from #form (it's a matter of picking the right selector) in the first line it will work on all of your forms on your website as long as you accuire all info needed in your form tag.[/B] Here's a simple snippet of how i process ajax forms with only a few lines of jQuery code. For this to work perfectly you will need jquery: - Include jquery in your mockup: [url]https://code.jquery.com/jquery-1.11.3.min.js[/url] A demo is live on [url]http://happyfoodstore.be[/url] (The contact form button footer) Send empty form if you'd like to test it, don't spam. (Just saw that captcha change was broken, i'm not responsible for the site anymore just once worked there.) jQuery has made Ajax a lot easier, instead of calling multiple functions depending on some states jQuery makes it possible to make an Ajax request with just the following code: [code] $("#form").submit(function(e) { var postData = $(this).serializeArray(); //The important part, no need to define any data key to an element, this way we can use our $_POST / $_GET tag the way we have set it up in our html by the input's name attribute. var formURL = $(this).attr("action"); var method = $(this).attr("method"); $.ajax( { url : formURL, //File to process the action type: method, //Post, get, put or delete ? ($_POST, $_GET, $_PUT, $_DELETE defined in the method attribute op the form tag) data : postData, //Will be accessible by it's name in the $_POST or $_GET arr. (Name of your inputs) success:function(data, textStatus, jqXHR) { $("[URL=http://www.runelocus.com/forums/usertag.php?do=list&action=hash&hash=form]#form[/URL] -response").html(data); //The div to place the response in. } }); e.preventDefault(); }); [/code] - This above jQuery code will make our form [URL=http://www.runelocus.com/forums/usertag.php?do=list&action=hash&hash=form]#form[/URL] submittable by Ajax - The action attribute in the form tag (HTML sided) wil determine where the ajax request is sent to (What URI?) - POST Data get's serialized automaticly, and you can use them in your action script like you have always used them before in PHP on a regular form submit ($_POST['key']) - Make sure div [URL=http://www.runelocus.com/forums/usertag.php?do=list&action=hash&hash=form]#form[/URL] -response is present in the HTML mockup (Most likely on top of the form) this will give us a response printed out from our action script. If we place the following code in our action script (The one the form action attribute points to): [code] <?PHP var_dump($_POST); [/code] Than we will have an array with all POST data to be shown to the users upon form submit. Our <div id="form-response"></div> (present in the HTML mockup) wil make sure the users get's to see the "action" response. In our case a whole Array of POST data values will be shown. Up to you to code your own form validation with error messages and on success a success message, those messages will be the printed data in your action script. And ofc, if you have multiple forms on your site you can code it in a way you only need to write it once. Ajax is a great way to handle all of your forms! It's up to you if you wanne use this great code or not. Don't reload your pages upon an action, instead use ajax to reduce server load and improve your UX. This method can be used by all kinds of actions, not only form sided, however this code was an example of how you should handle your forms with ajax. If you read the code than you should know how to use it on a simple button perhaps to load more products for example. NOTE: This wil not work on any browser that doesn't support javascript. (But to make u feel better: [url]http://www.w3counter.com/globalstats.php[/url] nearly no users use the real old browser software anymore which will make coding javascript only more and more convenient.) And ofcource a failsafe for this is you can code your action script for both the ajax response or a whole page reload response. If you realy don't get this, please let me know and i'l make time for you to explain it live. Regards, MiCa
  2. ive just downloaded the 508 client and server and followed the tutorial to do so and got them both working, ive tested as many skills as i possibly can and for some reason, no clients or accounts gain any XP whatsoever, i could bury 50 dragon bones and not gain 1 XP at all, how do i fix this?
  3. [code] if(myOffer.getType() == Type.BUY) { int freeSlots = player.getInventory().getFreeSlots(); if(freeSlots < myOffer.getAmount() && !ItemDefinition.forId(myOffer.getId()).isStackable()) { player.getInventory().addItem(myOffer.getId()+0, myOffer.getAmount()); player.offers[box].setId(-1); player.offers[box] = null; player.getActionSender().resetItemSlot(player, box); player.getActionSender().setGe(box, 0, -1, -1, -1, 0); } else if(freeSlots > myOffer.getAmount() || ItemDefinition.forId(myOffer.getId()).isStackable()) { player.getInventory().addItem(myOffer.getId(), myOffer.getAmount()); player.offers[box].setId(-1); player.offers[box] = null; player.getActionSender().resetItemSlot(player, box); player.getActionSender().setGe(box, 0, -1, -1, -1, 0); //player.getActionSender().resetGe(box); } } [/code] items aren't changing to noted form when u buy more than the amount of free space in your inventory i have changed the line else if(freeSlots > myOffer.getAmount() || ItemDefinition.forId(myOffer.getId()).isStackable()) to isNoted but it still doesn't change to noted form when u buy more than the amount of free inventory. or is there anyway it can be converted to buying the noted item
  4. [B]A Basic Contact Form Using A MySQL Database[/B] This tutorial will take you through all steps in making a simple contact me/us form that stores the information into a database. This will be a very basic yet fully functional script that you can go on to develop further or I may come back to in a few days/weeks if requested. First we're going to start with the structure of the database table and what each column does/mean. You will need to setup a MySQL database and a user that has privileges to that database first. So our table name for this will be, 'messages'. We will need: [LIST] [*]id (int) [*]name (TEXT) [*]email (VARCHAR) [*]message (VARCHAR) [*]date (DATE) [/LIST] You can run this following script under "SQL" in phpMyAdmin (in your database) [CODE] CREATE TABLE IF NOT EXISTS `messages` ( `id` int(8) NOT NULL AUTO_INCREMENT, `name` text NOT NULL, `email` varchar(100) NOT NULL, `message` varchar(1000) NOT NULL, `date` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; [/CODE] Now that we have our database, database user and table structure up we can begin with our PHP. We will be using a form that is running an action in the same file, so for the form action we use: [PHP]<?php echo $_SERVER['PHP_SELF']; ?>[/PHP] and just as normal we will be using post as the method. The start of the form should look a little like this: [HTML]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">[/HTML] I've gone ahead and I found a nice, basic style on the web. I won't be explaining anything to do with the style but here's the CSS you can attatch if you want: [CODE] @charset "utf-8"; /* CSS Document */ fieldset { width: 500px; } legend { font-size: 20px; } label.field { text-align: right; width: 100px; float: left; font-weight: bold; } [/CODE] Here's what my whole form looks like, I'll break it down into little parts but remember I'm not talking about the style (or much HTML) in anyway. [HTML] <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Shipping Address</legend> <label class="field" for="name">Name: </label><input type="text" name="name" /><br /> <label class="field" for="email">Email: </label><input type="text" name="email" /><br /> <label class="field" for="message">Message: </label><textarea cols="40" rows="10" name="message"></textarea><br /> <label class="field" for="submit"><input type='submit' name='submit' value='Submit Form' /></label> </fieldset> </form> [/HTML] The webpage should look somewhat like this: [IMG]http://surreal.raxweb.com/KZONw8.jpg[/IMG] I've already explained the action and method of the form, I'll now take the line for one of the inputs and explain it further: [HTML]<label class="field" for="name">Name: </label><input type="text" name="name" /><br />[/HTML] The above code includes the style, our script will still function if we only were to have: [HTML]Name: <input type="text" name="name" />[/HTML] The input tag is what shows the little input box, type="text" is simply all we need as we're saying that the input is going to hold text and as for name="name" this is how we will go about retrieving the value set in PHP ($_POST['name']). That's about all we need to know for the form, moving on to some PHP. So because we are limiting this done to only one page we need to tell the script when to show certain things, obviously we want to show the form BEFORE it has been submitted. We can do this by checking if the post variable for submit if set ([I]isset[/I]) or not. We can put our form in an [I]if[/I] statement that looks like this. [PHP]<?php if(!isset($_POST['submit'])) { ?> //form in here <?php } ?>[/PHP] So the if statement here is basically saying [I]if[/I] [I]$_POST['submit'][/I] is not set ([I]!isset[/I]) to then display whatever is between [I]{[/I] and [I]}[/I] which in our case is the form. After this our form now looks something like this: [PHP] <?php if(!isset($_POST['submit'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Shipping Address</legend> <label class="field" for="name">Name: </label><input type="text" name="name" /><br /> <label class="field" for="email">Email: </label><input type="text" name="email" /><br /> <label class="field" for="message">Message: </label><textarea cols="40" rows="10" name="message"></textarea><br /> <label class="field" for="submit"><input type='submit' name='submit' value='Submit Form' /></label> </fieldset> </form> <?php } ?> [/PHP] Simple, yeah? Now we're onto the part for when AFTER the form is complete. This time we're going to check if all inputs have been set using an [I]if[/I] statement and [I]isset[/I] (lets hope you remember). To check the name, email, message and submit all at once in a single [I]if[/I] statement we can use [I]and[/I]. Here's what I have: [PHP] if(isset($_POST['submit']) and isset($_POST['name']) and isset($_POST['email']) and isset($_POST['message'])) { //code here ?> [/PHP] Still following? That's nearly all of the simple stuff out of the way! To save time and make things easier for us we'll set our post variables to something easier by doing this: [PHP] if(isset($_POST['submit']) and isset($_POST['name']) and isset($_POST['email']) and isset($_POST['message'])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; } [/PHP] Now instead of using $_POST['whatever'] all the time we just use $whatever. To make life even more simple for us we want to set a datetime variable using PHP's [I]date[/I] function. [PHP]$datetime = date("d/m/y : H:i:s", time());[/PHP] This will throw us back something like this: [QUOTE]11/07/12 : 13:36:44[/QUOTE] Pretty self explanatory? d = day, m = month, y = year, H = hours (24), i = minutes and s = seconds. Have a play around with it and you'll understand it all better. Before we get onto PDO/SQL here's what your script should look like so far. [HTML] <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css.css" type="text/css" rel="stylesheet" /> <title>Surreal's Basic MySQL Contact Form</title> </head> <body> <?php if(!isset($_POST['submit'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Shipping Address</legend> <label class="field" for="name">Name: </label><input type="text" name="name" /><br /> <label class="field" for="email">Email: </label><input type="text" name="email" /><br /> <label class="field" for="message">Message: </label><textarea cols="40" rows="10" name="message"></textarea><br /> <label class="field" for="submit"><input type='submit' name='submit' value='Submit Form' /></label> </fieldset> </form> <?php } if(isset($_POST['submit']) and isset($_POST['name']) and isset($_POST['email']) and isset($_POST['message'])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $datetime = date("d/m/y : H:i:s", time()); } </body> </html> [/HTML] Now, using PDO is the fun part :D. A good read up on PDO can be found [URL="http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/"]here at TutsPlus[/URL]. For what we're doing today with just inserting your PDO code will end up looking a bit like this: [PHP] try { $dbh = new PDO("mysql:host=localhost;dbname=database_name", "database_user", "database_password"); $insert = $dbh->exec("INSERT INTO messages (name, email, message, date) VALUES ('$name', '$email', '$message', '$datetime')"); $dbh = null; } catch(PDOException $e){ echo $e->getMessage(); } [/PHP] To learn more about PDOException go [URL="http://php.net/manual/en/class.pdoexception.php"]here[/URL]. Okay so time to explain all this. The first line: [PHP]$dbh = new PDO("mysql:host=localhost;dbname=database_name", "database_user", "database_password");[/PHP] dbh stands for "Database Handle", you don't need to use dbh but I guess it's just best practice, you'll find most people will as you can easily identify it. [CODE]mysql:host=localhost;dbname=database_name", "database_user", "database_password[/CODE] The above is all stuff that we have to change/configure according to our web server/database. The host, in 90% of cases is localhost. There are some web hosts such as 000webhost that may have it different. dbname is simply the database that you would've created at the start. For cPanel users it looks something like cpanellogin_database. "database_user" is simply the username that you granted privileges to the database at the very start. Again for cPanel users it looks similiar to cpanellogin_user. "database_password" this should require any explanation what-so-ever. Simply the password to the database user. So that's all for the connection. Yay! [PHP]$insert = $dbh->exec("INSERT INTO messages (name, email, message, date) VALUES ('$name', '$email', '$message', '$datetime')");[/PHP] So this is simply executing (exec) a SQL query through our connection ($dbh). [CODE]INSERT INTO messages[/CODE] The code above means that it's going to enter information that is following the columns. We left out id as id is going to automatically increment +1 for each entry. [CODE](name, email, message, date)[/CODE] The above is the columns that we want to insert data into, the order is, of course important. [CODE]VALUES ('$name', '$email', '$message', '$datetime')[/CODE] Remember how we set our post variables to something simpler? Well here they are! VALUES is simply giving the values in which they will be imported into the opposing column. name was the first column so the string/information the user originally inputted into the form and which we saved as $name will be inserted into that column as they are both first, then email and $email and so on... The final thing we MUST remember to do is to close the connection, for PDO we simply add the following line under our query('s). [PHP]$dbh = null;[/PHP] This will kill the connection. Wohooo! We've made it! Now you have a very basic contact form that stores the information into your database. You can edit this script further to maybe add a CAPTHCA/anti-bot or there's a wide range of features that can be added using the skills learned in this tutorial! Here's the finished script so you can check over incase of any errors/mistakes you may have made: [PHP] <!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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="css.css" type="text/css" rel="stylesheet" /> <title>Surreal's Basic MySQL Contact Form</title> </head> <body> <?php if(!isset($_POST['submit'])) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Shipping Address</legend> <label class="field" for="name">Name: </label><input type="text" name="name" /><br /> <label class="field" for="email">Email: </label><input type="text" name="email" /><br /> <label class="field" for="message">Message: </label><textarea cols="40" rows="10" name="message"></textarea><br /> <label class="field" for="submit"><input type='submit' name='submit' value='Submit Form' /></label> </fieldset> </form> <?php } if(isset($_POST['submit']) and isset($_POST['name']) and isset($_POST['email']) and isset($_POST['message'])) { $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $datetime = date("d/m/y : H:i:s", time()); try { $dbh = new PDO("mysql:host=localhost;dbname=database_name", "database_user", "database_password"); $insert = $dbh->exec("INSERT INTO messages (name, email, message, date) VALUES ('$name', '$email', '$message', '$datetime')"); $dbh = null; } catch(PDOException $e){ echo $e->getMessage(); } } ?> </body> </html> [/PHP] This tutorial took me a bloody long time so feedback will be hugely appreciated! I actually didn't get the chance to test this yet but will do soon/tomorrow. Any mistakes you see be sure to tell me! :D Thank you :)
  5. Okay so I have this form [PHP]<?php $result = mysql_query("SELECT * FROM queue ORDER BY id"); while($details = mysql_fetch_array($result)){ $priceone = $details['minprice']; $pricetwo = $details['midprice']; $pricethr = $details['maxprice']; $name = $details['name']; $change = $details['lastprice']; $value = $details['value']; $iid = $details['id']; $id2 = $details['id2']; echo "<tr align=\"center\">"; echo "<td class=\"small\">". $details['user'] ."</td>"; echo "<td class=\"small\"><a href=\"item.php?i=".$id2."\">". $name ."</a></td>"; echo "<td class=\"small\"><img src=\"". $details['image'] ."\" /></td>"; echo "<td class=\"small\">". $priceone ." (<strong>". $pricetwo ."</strong>) ". $pricethr ."</td>"; echo "<td class=\"small\">". $change ."</td>"; echo "<td class=\"small\">". $value ."</td>"; $change = str_replace("+", "PLUS", $change); echo "<td class=\"small\"> <a href=\"?id=$iid&delete=false&accept=true&value=$value&mid=$pricetwo&min=$priceone&max=$pricethr&change=$change&rid=$id2\">Yes</a> / <a href=\"?id=".$iid."&delete=true&accept=false\">No</a></td>"; echo "</tr>"; } ?>[/PHP] and i have the operations for it... [PHP]<?php $id = mysql_real_escape_string(trim($_GET['id'])); $delete = mysql_real_escape_string(trim($_GET['delete'])); $accept = mysql_real_escape_string(trim($_GET['accept'])); $rid = mysql_real_escape_string(trim($_GET['rid'])); $value = mysql_real_escape_string(trim($_GET['value'])); $midprice = mysql_real_escape_string(trim($_GET['mid'])); $minprice = mysql_real_escape_string(trim($_GET['min'])); $maxprice = mysql_real_escape_string(trim($_GET['max'])); $change = $_GET['change']; $change = str_replace("PLUS", "+", $change); if ($id > 0) { if ($delete == "true" && $accept == "false") { $sql = mysql_query("DELETE FROM queue WHERE id = $id"); mysql_query($sql); die("row has been deleted from database, row id: ".$id); } if ($delete == "false" && $accept == "true") { $sql = mysql_query("DELETE FROM queue WHERE id = $id"); mysql_query($sql); mysql_query("UPDATE item SET value = '$value', minprice = '$minprice',midprice = '$midprice', maxprice = '$maxprice', lastprice = '$change' WHERE id = '$rid'") or die(mysql_error()); die("row has been executed and item information has been updated, row id: ".$id); } die("id = ".$id." / delete = ".$delete." / accept = ".$accept); } ?>[/PHP] it works fine and all however i want it to be... less messy? this is probably done in the worse way possible i'm sure if anyone can rewrite it a bit to make it so it reads all the fields without me forcing all the fields into the url of it :P for example, right now i have it set to query if the url is like this [CODE]http://site.com/file.php?id=$iid&delete=false&accept=true&value=$value&mid=$pricetwo&min=$priceone&max=$pricethr&change=$change&rid=$id2\[/CODE] any help/tips would be appreciated
×