PHP - Question About Isset, Making Form Fields Required...
If I wanted to make multiple fields required before letting a User move past the field is this the proper way to do it?
Code: [Select] if(isSet($_POST['playerFirst']['playerLast']['feet']['inches']['year']['status'])) { ## Something } else { ## Something else } Similar TutorialsHi I am learning PHP and working on a Contact Us page with a required fields. For some reason it works great for the name and email, but always says please enter your phone number. If you guys have a better way of doing this please let me know. Also if the email is sent successfully I want it to goto the page "success.html" this part works good though just need some help please Here is the form: Code: [Select] <form action="contact.php" method="post" id="contactform"> <ol> <li> <label for="name">Full Name <span class="red">*</span></label> <input id="name" name="name" class="text" /> </li> <li> <label for="email">Your email <span class="red">*</span></label> <input id="email" name="email" class="text" /> </li> <li> <label for="phone">Phone Number <span class="red">*</span></label> <input id="phone" name="phone" class="text" /> </li> <li> <label for="company">Company</label> <input id="company" name="company" class="text" /> </li> <li> <label for="topic">Subject<span class="red">*</span></label> <input id="topic" name="topic" class="text" /> </li> <li> <label for="comments">Message <span class="red">*</span></label> <textarea id="comments" name="comments" rows="6" cols="50"></textarea> </li> <li class="buttons"> <input type="image" name="imageField" id="imageField" src="images/send.gif" /> </li> </ol> </form> The PHP code I tried: Code: [Select] <?php // Pick up the form data and assign it to variables $name = check_input ($_POST['name'], "Please enter your name"); $email = check_input ($_POST['email'],"Please enter your email"); $phone = check_input ($_POST['phone'], "Please enter your phone number"); $company = $_POST['company']; $topic = check_input ($_POST['topic'], "Please enter your subject"); $comments = check_input ($_POST['comments'], "Please enter your message"); function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if (strlen($data) == 0) { die($problem); } else { return $data; } } // Build the email (replace the address in the $to section with your own) $to = 'email@email.com"'; $subject = "New message: $topic"; $message = "Email: $email \n Phone: $phone \n Company: $company \n $name said: $comments"; $headers = "From: $email"; // Send the mail using PHPs mail() function mail($to, $subject, $message, $headers); // Redirect header("Location: success.html"); ?> I was able to make my fields required and the user gets a message and has to go back and enter all of the required fields before they see a successful submission, but I still get an email every time they get the error message. Below is the code, thanks so much for your help. (fyi, i got all of the code from the web and changed to fit my needs, so I'm not entirely sure what it all does, if i had to guess, i would think the problem is in "$sent = mail($to, $subject, $body, $headers);", but that's just a guess) Code: [Select] <?php $to = "email@mydomain.com"; $email = $_REQUEST['email'] ; $fname = $_REQUEST['fname'] ; $lname = $_REQUEST['lname'] ; $phone = $_REQUEST['phone'] ; $type = $_REQUEST['type'] ; $details = $_REQUEST['details'] ; $subject = "Message from: $fname $lname"; $headers = "noreply@mydomain.com"; $body = "FirstName: $fname \n\n Lastname: $lname \n\n PhoneNumber: $phone \n\n Email: $email \n\n Type: $type \n\n Details: $details \n\n"; $sent = mail($to, $subject, $body, $headers) ; if ($_POST['fname']=="") { Print("Ooops, please use your back button and provide your first name!<br>"); } elseif ($_POST['lname']=="") { Print("Ooops, please use your back button and provide your last name!<br>"); } elseif ($_POST['phone']=="") { Print("Ooops, please use your back button and provide your phone number!<br>"); } elseif ($_POST['email']=="") { Print("Ooops, please use your back button and provide your email!<br>"); } elseif($sent) {echo "<script language=javascript>window.location = 'thanks.php';</script>";} else {echo "<script language=javascript>window.location = 'error.php';</script>";} ?> i need help in this form Code: [Select] <FORM action="thanx.php" method="post"> <TABLE width="100%" border=0> <TBODY> <TR> <TD align=center><FONT color=#ff0000>* </FONT>title:<BR><INPUT size=40 name=title><BR></TD> </TR> </TBODY> <TABLE width="100%" border=0> <TBODY> <TR> <TD align=center><FONT color=#ff0000>* </FONT>Url<BR><INPUT size=40 name=url value=http://><BR><TD></TR></TBODY></TABLE> </TD> </TR> <TABLE width="100%" border=0> <TBODY> <TR> <TD align=center>description<BR> <textarea cols="50" rows="4" name="description"></textarea><BR><TD></TR></TBODY></TABLE> </TD> </TBODY></TABLE> <P style="TEXT-ALIGN: center" align=center><INPUT class=submit type=submit value="add" name=send></TD> </FORM> first : i want make fields required "at lest Three letters" using php not java ... but i want the user don't leave the form if this fields empty .. and i need the user don't go the add.php if this fields empty like :: please fill the blank fields second : some time my users post in the in fields ..something like this Code: [Select] <SCRIPT type=text/javascript> <!-- //--> </SCRIPT> or something like this Code: [Select] <a href=""</a> and some time user write one letter in the field i don't accept this ..because it makes problems in the results.. so what can i do to fix this and make security for this . so can anyone help me ..please Hi Everyone, I am a great fan of the 'isset' function, which I use alot when submitting forms, but not wanting to navigate away from the page. Normally I just use a form with a submit button with a name, for example: Code: [Select] <input type='submit' name='updatetable' value='Go!'/> and then use the following: <?php if (isset ($_POST['updatetable'])) { do this stuff... } ?> But I want to start to use images as submit buttons, so when you click on them, you are able to submit the underlying data. Is there a way to do this using the isset function? Because effectively, the image, which would submit using javascript, wont have a name. Any ideas appreciated Many Thanks Matt I need to check whether the user has uploaded a file when submitting a form using isset. If they have, the file path is recorded to the database. If they haven't nothing needs to occur, the file path field will just be NULL. Here is my issue: When I test it with uploading no file I'm still getting "images/" from my $ filelocation variable recorded to the database. How can I fix this? <?php if(isset($_FILES['userfile'])) { $fileupload = $_FILES['userfile']['name']; $filetype = $_FILES['userfile']['type']; $filesize = $_FILES['userfile']['size']; $tempname = $_FILES['userfile']['tmp_name']; $filelocation = "images/$fileupload"; } else { $filelocation = NULL; } if (!move_uploaded_file($tempname,$filelocation)) { switch ($_FILES['userfile']['error']) { case UPLOAD_ERR_INI_SIZE: echo "<p>Error: File exceeds the maximum size limit set by the server</p>" ; break; case UPLOAD_ERR_FORM_SIZE: echo "<p>Error: File exceeds the maximum size limit set by the browser</p>" ; break; default: echo "<p>File could not be uploaded </p>" ; } } if ($_POST["productName"] == "") { header("Location:getProductDetails.php"); exit(); } elseif ($_POST["productDescription"] == "") { header("Location:getProductDetails.php"); exit(); } else { $conn = @mysqli_connect("localhost", "root", ""); if (!$conn) { echo "The connection has failed: " . mysqli_error($conn); } else { //echo "Successfully connected to mySQL!"; $query = "CREATE DATABASE IF NOT EXISTS bazaar"; $dbName =""; if (!mysqli_query($conn,$query)) { echo "<p>Could not open the database: " . mysqli_error($conn)."</p>"; } else { //echo "<p>Database successfully created</p>"; if (!mysqli_select_db($conn,"bazaar")) { echo "<p>Could not open the database: " . mysqli_error($conn)."</p>"; } else { //echo "<p>Database selection successful</p>"; $query = "CREATE TABLE IF NOT EXISTS products(productid int primary key not null auto_increment,productname varchar(50), productdesc text, colour varchar(25), price decimal(5,2) not null,imagepath varchar(250));"; if (!mysqli_query($conn,$query)) { echo "table query failed1: " . mysqli_error($conn); } else { //echo "<p>table query successful</p>"; $insert = "INSERT INTO products (productname, productdesc, colour, price, imagepath) VALUES ('$_POST[productName]','$_POST[productDescription]','$_POST[colour]','$_POST[price]','$filelocation');"; if (mysqli_query($conn,$insert)) { $customerId = mysqli_insert_id($conn); } else { echo "table query failed: " . mysqli_error($conn); } } } } } mysqli_close($conn); } ?> 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 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'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> 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! 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> 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 I read ages ago (and checked to see if it's true, it was and given how it works, it must still be) the end user can alter the value of any form field, using Firebug or similar, before submitting it. Two things I've figured out today: 1) a form input doesn't need a value - doesn't even need the attribute - if you're only checking whether the POST var isset and the actual value isn't important 2) Although it appears not to matter in the example I'm working on now, if the script doesn't check what the value is, and potentially sanitise it, the user could submit the form with any value, true, false, malicious, idk... So my question is: is this one of the ways malicious bad things can happen and do I *have to* specify a value, not because the script won't work without it, it does, but because in the real world it opens a security door if I don't check for malicious script by saying "if value not as expected, script has to die". Having formulated the question properly and thought about it I can't imagine simply making a form, without obvious connections to anything important, could be a problem in the way I'm asking about but I asked it now so Edited by appobs, 03 July 2014 - 12:08 PM. Hi all, I have the below which is meant to check if the required fields in a form have been submitted, however when submit is clicked, even with no values in the boxes, the form submits as normal. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include_once ('formvalidator.php'); ?> <link href="../Styles/form_dark.css" rel="stylesheet" type="text/css" /> <?php $show_form=true; if(isset($_POST['submit'])) { $validator = new FormValidator(); $validator->addValidation("user_name","req","Please fill in Name"); $validator->addValidation("user_password","req","Please enter a password"); $validator->addValidation("user_email","email", "The input for Email should be a valid email value"); $validator->addValidation("user_email","req","Please fill in Email"); if($validator->ValidateForm()) { echo "<h2>Validation Success!</h2>"; $show_form=false; } else { echo "<B>Validation Errors:</B>"; $error_hash = $validator->GetErrors(); foreach($error_hash as $inpname => $inp_err) { echo "<p>$inpname : $inp_err</p>\n"; } } } if(true == $show_form) { ?> <form class="dark" action="regdo.php" method="post" > <ol> <li> <fieldset> <legend>User Registration</legend> <ol> <li> <label for="user_name">Username</label> <input type="text" id="user_name" name="user_name" value="" /> </li> <li> <label for="user_email">E-Mail Address</label> <input type="text" id="user_email" name="user_email" value="" /> </li> <li> <label for="user_password">Password</label> <input type="password" id="user_password" name="user_password" value="" /> </li> </ol> </fieldset> </li> </ol> <p style="text-align:right;"> <input type="reset" value="CANCEL" /> <input type="submit" value="OK" /> </p> </form> <?php }//true == $show_form ?> Can anyone explain what the problem is? Cheers Hi- the code below lets me upload a CSV file to my database if I have 1 field in my database and 1 column in my CSV. I need to add to my db "player_id" from the CVS file and "event_name" and "event_type" from the form... any ideas??? here's the code: Code: [Select] <?php $hoststring =""; $database = ""; $username = ""; $password = ""; $makeconnection = mysql_pconnect($hoststring, $username, $password); ?> <?php ob_start(); mysql_select_db($database, $makeconnection); $sql_get_players=" SELECT * FROM tabel ORDER BY player_id ASC"; // $get_players = mysql_query($sql_get_players, $makeconnection) or die(mysql_error()); $row_get_players = mysql_fetch_assoc($get_players); // $message = null; $allowed_extensions = array('csv'); $upload_path = '.'; //same directory if (!empty($_FILES['file'])) { if ($_FILES['file']['error'] == 0) { // check extension $file = explode(".", $_FILES['file']['name']); $extension = array_pop($file); if (in_array($extension, $allowed_extensions)) { if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path.'/'.$_FILES['file']['name'])) { if (($handle = fopen($upload_path.'/'.$_FILES['file']['name'], "r")) !== false) { $keys = array(); $out = array(); $insert = array(); $line = 1; while (($row = fgetcsv($handle, 0, ',', '"')) !== FALSE) { foreach($row as $key => $value) { if ($line === 1) { $keys[$key] = $value; } else { $out[$line][$key] = $value; } } $line++; } fclose($handle); if (!empty($keys) && !empty($out)) { $db = new PDO( 'mysql:host=host;dbname=db', 'user', 'pw'); $db->exec("SET CHARACTER SET utf8"); foreach($out as $key => $value) { $sql = "INSERT INTO `table` (`"; $sql .= implode("`player_id`", $keys); $sql .= "`) VALUES ("; $sql .= implode(", ", array_fill(0, count($keys), "?")); $sql .= ")"; $statement = $db->prepare($sql); $statement->execute($value); } $message = '<span>File has been uploaded successfully</span>'; } } } } else { $message = '<span>Only .csv file format is allowed</span>'; } } else { $message = '<span>There was a problem with your file</span>'; } } ob_flush();?> <!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" /> <title>CSV File Upload</title> </head> <body> <form class="form" action="" method="post" enctype="multipart/form-data"> <h3>Select Your File</h3> <p><?php echo $message; ?></p> <input type="file" name="file" id="file" size="30" /> <br/> <label>Event Name:</label><input name="event_name" type="text" value="" /> <br/> <label>Event Type:</label><input name="event_type" type="text" value="" /> <br/> <input type="submit" id="btn" class="button" value="Submit" /> </form> <br/> <h3>Results:</h3> <?php do { ?> <p><?php echo $row_get_players['player_id'];?></p> <?php } while ($row_get_players = mysql_fetch_assoc($get_players)); ?> </body> </html> In one of my pages I have a section which contains a hidden line of text. When the user clicks a button the box containing the text will expand showing the line more clearly. I want this to happen live i.e. no page refresh/reload. I've seen such things done on other sites but my question is, is this done using a php function or is JavaScript required to achieve this? I assume that in order for any php functions to take place there must be a page refresh to reload the data/parameters/variables that are required? The site I'm referring to is this one:- http://www.vouchercodes.co.uk/featured-voucher-codes.html If you click on the "Get code and open site" buttons there for any of the vouchers the area expands live and the voucher is revealed however as I say there is no page refresh and it is done live. Is this effect done in JavaScript and not php or is there some way of using php alone to do something similar? Obviously including JScript in a site is more risky as if a user does not have it installed/activated then they may not be able to use such elements hence the reason I want to know how it is done. Hi Guys i need help on a small matter. if you go to https://www.mywebchambers.co.uk/invoiceman/form.php when submitted all works ok. However if you delete rows 3, 4 and 5 and submit the page shows a value of 0.00 in the total column on rows 3, 4 and 5. How do i get this value removed so it is blank same as the rest ?
My form action is toolstation3.php code below
<!doctype html> <?php
{$orderno =($_POST["orderno"]);}
{$code3 =($_POST["code3"]);}
{$code4 =($_POST["code4"]);}
{$code5 =($_POST["code5"]);}
{$sum1 =($_POST["sum1"]);} {$nil =($_POST["nil"]);}
$net=$sum1+$sum2+$sum3+$sum4+$sum5;
$total=$net+$vat;
$sum1 = number_format($sum1, 2, '.', '');
if(empty($_POST['quantity3']) && empty($_POST['price3'])) {echo " $nil";}
echo "<br>   ____________________________________________________________________________________________________<br><br>"; echo "<H3>    Address                                                                                                                     Details "; echo "<br>   ___________________________________________________________          ____________________________________<br><br>";
echo "<tr>
echo "<tr> echo "<table cellpadding=3 border=0 style='float:left'>";
echo "<tr> echo "<table cellpadding=3 border=0 style='float:left'>";
echo "<tr> echo "<table cellpadding=3 border=0>";
echo "<tr> echo "<H3>    Items"; echo "<br>   __________________________________________<br><br>";
echo "<tr><th>Code</th><th>Name</th><th>Quantity</th><th>Price</th><th>Total</th><th>Vat Band</th></tr>"; echo "<tr><td>$code1</td><td>$name1</td><td>$quantity1</td><td>$price1</td><td>$sum1</td><td>$vatband1</td> "; echo "<tr><td>$code2</td><td>$name2</td><td>$quantity2</td><td>$price2</td><td>$sum2</td><td>$vatband2</td> "; echo "<tr><td>$code3</td><td>$name3</td><td>$quantity3</td><td>$price3</td><td>$sum3</td><td>$vatband3</td> "; echo "<tr><td>$code4</td><td>$name4</td><td>$quantity4</td><td>$price4</td><td>$sum4</td><td>$vatband4</td> "; echo "<tr><td>$code5</td><td>$name5</td><td>$quantity5</td><td>$price5</td><td>$sum5</td><td>$vatband5</td> ";
echo "<br>"; echo "<H3>    VAT Analysis"; echo "<br>   __________________________________________<br><br>"; echo "<table cellpadding=5 border=1>"; echo "<tr><th>Band</th><th>Rate</th><th>Net</th><th>VAT</th><th>Total</th></tr>"; echo "<tr><td>5</td><td>20%</td><td>$net</td><td>$vat</td><td>$total</td> ";
<div id="container">
I need help with a form .. My form needs to allow an additional drop down field for Groups. This form also needs to save the extra fields chosen into my MySQL DB. Here is my form.. Code: [Select] <form action='' method='post' class='assessment'> <h1>Create User</h1> <div class='label'>First Name</div> <div class='field'><input type='text' name='firstname' value='<?=$preUser->firstname?>' /></div> <div class='cb'></div> <div class='label'>Last Name</div> <div class='field'><input type='text' name='lastname' value='<?=$preUser->lastname?>' /></div> <div class='cb'></div> <div class='label'>Password</div> <div class='field'><input type='text' name='password' value='<?=$preUser->password?>' /></div> <div class='cb'></div> <div class='label'>Company</div> <div class='field'><input type='text' name='company' value='<?=$preUser->company?>' /></div> <div class='cb'></div> <div class='label'>Job Title</div> <div class='field'><input type='text' name='job' value='<?=$preUser->job?>' /></div> <div class='cb'></div> <div class='label'>Group Name</div> <div class='field'><select name='group'><?=$groupSelect?></select></div> <div class='cb'></div> <div class='label'>Address</div> <div class='field'><input type='text' name='street1' value='<?=$preUser->street1?>' /></div> <div class='cb'></div> <div class='label'>Address (optional)</div> <div class='field'><input type='text' name='street2' value='<?=$preUser->street2?>' /></div> <div class='cb'></div> <div class='label'>City</div> <div class='field'><input type='text' name='city' value='<?=$preUser->city?>' /></div> <div class='cb'></div> <div class='label'>State</div> <div class='field'><input type='text' name='state' value='<?=$preUser->state?>' /></div> <div class='cb'></div> <div class='label'>Postal Code</div> <div class='field'><input type='text' name='postal' value='<?=$preUser->postal?>' /></div> <div class='cb'></div> <div class='label'>Country</div> <div class='field'><input type='text' name='country' value='<?=$preUser->country?>' /></div> <div class='cb'></div> <div class='label'>Fax</div> <div class='field'><input type='text' name='fax' value='<?=$preUser->fax?>' /></div> <div class='cb'></div> <div class='label'>Phone</div> <div class='field'><input type='text' name='phone1' value='<?=$preUser->phone1?>' /></div> <div class='cb'></div> <div class='label'>Phone 2</div> <div class='field'><input type='text' name='phone2' value='<?=$preUser->phone2?>' /></div> <div class='cb'></div> <div class='label'>Email</div> <div class='field'><input type='text' name='email' value='<?=$preUser->email?>' /></div> <div class='cb'></div> <div class='label'>Website</div> <div class='field'><input type='text' name='website' value='<?=$preUser->website?>' /></div> <div class='cb'></div> <div class='label'>Photo</div> <div class='field imgupload'> <input type='hidden' name='photo' /> <? if( $preUser->photo ){ ?> <img src="../<?=$preUser->photo?>" style="height:300px; float:left;" /> <span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="<?=$preUser->photo?>">x</span> <? }else{ ?> <iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe> <? } ?> </div> <div class='cb'></div> <div class='label'>Payment Option</div> <div class='field'> <input type='radio' name='payment' value='Pay' <? if( $preUser->payment == 'Pay' ) echo "checked='checked'"; ?> />Pay<br /> <input type='radio' name='payment' value='NonPaid' <? if( $preUser->payment == 'NonPaid' ) echo "checked='checked'"; ?> />NonPaid </div> <div class='cb'></div> <div class='label'>Dashboard Options</div> <div class='field'> <div><input type='checkbox' name='mysteps' <? if( $preUser->mysteps ) echo "checked='checked'"; ?> value='1' />My Steps</div> <div><input type='checkbox' name='mycalendar' <? if( $preUser->mycalendar ) echo "checked='checked'"; ?> value='1' />My Calendar</div> <div><input type='checkbox' name='myprofiles' <? if( $preUser->myprofiles ) echo "checked='checked'"; ?> value='1' />My Profile</div> <div><input type='checkbox' name='myplans' <? if( $preUser->myplans ) echo "checked='checked'"; ?> value='1' />My Plans</div> </div> <div class='cb'></div> <div class='submit_assessment'><input type='submit' name='create_user' class='submit' value='Create User' /> <input type='button' value='Back' class='back' name='admin_create' /></div> <div class='cb'></div> </form> <script> function setUploadedImage(flink){ $('.imgupload > input:first').after('<img src="../'+flink+'" style="height:300px; float:left;" /><span class="rmimage" style="color:red; cursor:pointer; font-size:20px;padding-left:15px;" alt="'+flink+'">x</span>'); $('.imgupload > iframe:first').remove(); $('.imgupload > input:first').val(flink); } $('.rmimage').live('click', function (){ $(this).prev().prev().val(''); $(this).prev().remove(); $(this).after('<iframe src="../view/photo_upload.php" frameborder="0" scrolling="no" width="300" height="30"></iframe>'); $.post('../ajax/admin.php',{remove_image:$(this).attr("alt")}); $(this).remove(); }); </script> the specific area in question is this... Code: [Select] <div class='label'>Group Name</div> <div class='field'><select name='group'><?=$groupSelect?></select></div> I need to be able to add another dropdown list to allow for multiple group selections that get saved into the DB once submitted. How do I go about doing this?????? I have got another of those problems that should be easy to solve but I cannot get my head round it! I have a form to enter data into a table and one of the fields can be left blank. However, I'd data is entered in the field it can be a Zero. This is leaving me a problem as I cannot find a way to get the script to insert NULL if the field is blank but actually put the Zero in if that is what is entered. I have tried several permutations of nested if's using empty or isset, but whatever I try, the same result is inserted in both scenarios. The arguments I need to pass are...... If field is empty INSERT null If field is 0 INSERT 0 If field is not empty and not 0 INSERT field Thanks in advance for any suggestions. Steve Hello. So I already know an extremely elementary way to check to see if a form field is blank using PHP. For example: Code: [Select] if ($subject == "") The question I have is, is there a way to have php check every field in a form to make sure it has some sort of value? I want to create an 'if' statement which basically says, "If all form fields have something filled in, then do this" For example Code: [Select] if ($subject == "any value") & ($name == "any value") & ($comment == "any value") Not sure if that makes sense. Any help would be greatly appreciated!!! |