PHP - Associate Hidden Field With Check Box
so I have this code:
Code: [Select] <input type='checkbox' name='title8' value='$title8' /></td><td><strong>$title8</strong> <br /> $date8 <br />$ $price8<input type='hidden' name='price8' value='$price8'> how do I make is so that the hidden field is only going to submit if the checkbox is checked........ Similar TutorialsCode: [Select] Array ( [Comment] => Array ( [post_id] => 1 [name] => cc [email] => [body] => spam ) ) How can i check if email is empty or not? Is there any php built in function? Should i use foreach? (Another quite newbie...) I have already an online booking form. The Form works fine now and I would like to add on one more issue, but the code ignores what I want to check. I have 4 fields: arrival, departure, no. of persons and comments to check. Scenario 1: All field mentioned above are emtpty: Workes fine and message appears: "You have not provided any booking details". Scenario 2: If arrival (date_start) and departure (date_end) is entered, there should be at least an entry either in the field "comment", or in the field "pax". If not, there should be a message: "You have not provided sufficient booking details". INSTEAD: The booking request is sent, which should not be the case. The code is currently: # all fields empty : arrival, departure, pax and comments - error if(empty($data_start) && empty($data_end) && empty($pax)&& empty($comment)){ exit("You have not specified any booking details to submit to us. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } #If arrival and departure date is entered, there should be at least an entry either in the field "comment", or in the field "pax". if(!isset($data_start) && !isset($data_end) && empty($pax) && empty($comment)){ exit("You have not provided sufficient booking details. <br>Please use your browser to go back to the form. <br>If you experience problems with this Form, please e-mail us"); exit; } The form can be tested at http://www.phuket-beachvillas.com/contact-own/contact-it.php Can someone please check and tell me what's wrong with the code ? Thanks to anyone for any hint. I have a while loop that fetches data from the database and prints it out organized in a table. Now I want to implement a voting functionality, the problem I'm encountering is, once I've printed out a list of tables one table after other with the while loop I need to figure out a way to tell the query TO WHICH of those tables to ADD or SUBTRACT the vote. I thought of implement a hidden id field into the while loop of contributions, the id field would be fetched from the auto_increment field in the contribution table in the MySQL database. Since the id field is unique there can be no misunderstandings to which table to add the vote. My question how can I do exactly that? How can I add a hidden id field to the while loop with the table WHICH I then can pass along to the voting script. Here's the while loop: while ($row = mysqli_fetch_array($data)) { echo "<table padding='0' margin='0' class='knuffixTable'>"; echo "<tr><td width='65px' height='64px' class='avatar_bg' rowspan='2' colpan='2'><img src='$avatar_path' alt='avatar' /></td><td class='knuffix_username'><strong>" . $user_name; echo "</strong><br />" . $row['category'] . " | " . date('M d, Y', strtotime($row['contributed_date'])) . "</td></tr><tr><td>"; echo "<form action='' method='post'> <input type='submit' name='plusVote' value='Y' /> <input type='submit' name='minusVote' value='N' /> </form></td><td class='votes'>Y[ - ] | N[ - ]</td></tr>"; echo "<tr><td class='knuffix_name' colspan='3'><strong>" . htmlentities($row['name']) . "</strong><br /></td></tr>"; echo "<tr><td colspan='2' class='knuffix_contribution'><pre>" . $row['contribution'] . "</pre><br /></td></tr>"; echo "</table>"; } If I simply add $row['con_id'] it's obviously going to be echo'd out, what is the right practice to have it hidden? Hi all Basically, I have a form which when done will calculate a quote for turf for given areas. Basically each time the user specifies an area it goes into an array, and they can add as many as they want, but the problem seems to be once submitted and it arrives back into the program, it isn't decoding so the multidimensional array is lost. What am I doing wrong here? Full code below, thanks in advance Ste Code: [Select] <?php // Framework // Get the sections $sections_array = base64_decode(unserialize($_POST['sections'])); // Build the rest of the array foreach ($sections_array as $section) { $sections[] = base64_decode(unserialize($section)); } // Set the initial unit $units = $_POST['units']; // Do the new add if ($_POST['a'] == 'add_section') { // Add the new measure if ((is_numeric($_POST['width'])) && (is_numeric($_POST['length']))) { $sections[] = array('length' => $_POST['length'], 'width' => $_POST['width']); } } // Build the output foreach ($sections as $section) { $output .= '<strong>'.$section['width'].' wide</strong> x <strong>'.$section['length'].' long</strong><br />'; $sections_array = base64_encode(serialize($section)); } ?> <!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>Untitled Document</title> <style type="text/css"> body,td,th { font-family: Verdana, Geneva, sans-serif; font-size: 11px; } body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .wrap { text-align: center; height: 350px; width: 410px; padding: 0 10px; } </style> </head> <body> <div class="wrap"> <h2>Turf Calculator</h2> <p>To begin, enter the width and length of the first area of garden you wish to turf. You can keep adding sections to work out the final quantity required.</p> <p><?php echo $output; ?></p> <form id="form1" name="form1" method="post" action=""> <table width="0" border="0" cellspacing="0" cellpadding="2"> <tr> <td>Length:</td> <td><input type="text" name="length" id="length" /></td> </tr> <tr> <td>Width:</td> <td><input type="text" name="width" id="width" /></td> </tr> <?php if ($units == '') { ?> <tr> <td>Units:</td> <td><select name="units" id="units"> <option value="feet">Feet</option> <option value="m" selected="selected">Metres</option> <option value="yards">Yards</option> </select></td> </tr> <?php } ?> </table> <p> <input type="submit" name="add" id="add" value="Add This Section" /> <input name="a" type="hidden" id="a" value="add_section" /> <input name="sections" type="hidden" id="sections" value="<?php echo base64_encode(serialize($sections_array)); ?>" /> <?php if ($units != '') { ?> <input name="units" type="hidden" id="units" value="<?php echo $units; ?>" /> <?php } ?> </p> </form> <p> </p> </div> </body> </html> hidden input field type doesnt display the full value i get from table, say if it is a first name and last name i get only the first name. here is my input field echo "<input type=hidden name=proid value=$result_row[project_id]></include>"; echo "<input type=text value=$result_row[project_name] readonly></include>"; my sql query returns the full name but when i input into the text field it returns an incomplete project name like say if it is fans of soccer, i just get the value "fans" in my display..... I have this script running: <?php $query = mysql_query("SELECT * FROM jobs WHERE event = 'Yes' ORDER BY title"); while ($row = mysql_fetch_array($query)) { ?> How do I check if a field is empty and NOT display it...? For instance it has a 'applied' field, if that is empty I dont want it to display, however I still need the event = 'Yes' part. Ok so i have registration page on my webs but i didn't work on empty fields so how could i check all fields? Code: [Select] //if no name if(!$name){ $error = "Username missing."; } //if no pass if($pass == false){ $error = "$error,Password missing"; } //if no pass conf if($pass_conf == false) { $error = "$error,Pass conf missing."; } //if no email if($email == false){ $error = "$error,Email missing."; } //pass conf if($pass != $pass_conf){ $error = "$error,Passwords do not match."; } echo "<script>alert('$error');</script>;"; //header("Location: register.php"); My script gives same results every time (even if i fill any of fields)...also if i un-comment header command it wont show alert..it just reloads the page So can anyone help me with this? Thanks.. Hey all. What is the best way to check if a form field has been entered by the user? Because a field left blank by the user still shows up as set with the isset function. Example: if (isset($_POST['name'])) { echo "The field is set"; } This is a problem if I'm checking if the user has skipped over the name field on a form because an empty value gets passed to the POST array even if the field is left blank. Do people use empty or a regular expression instead? Cheers! I have a code which I made just up Code: [Select] <?php if ($product->title == '01'); print "Earring"; ?> <?php if ($product->title == '02'); print "Necklace"; ?> <?php if ($product->title == '03'); print "Necklace"; ?> <?php if ($product->title == '04'); print "Ring"; ?>I just want to check the product titles first 2 characters and print according to that. Example: If $product->title is "01DSE32" print Earring. This checking must be strgn or something like that which I don't remember. I would appreciate some feedback. Pehaps this is kidstuff but i'm a kid at heart. I have only 1 form field on a form User enters a special code in the form. Once submitted the form is queried against a mysql database to see if the code exists. If code does not exist it must be reentered. If code exists then redirected. basically its like "get to the next page if you have the code" thanks Hi there once again, sry for previous wrong section, i guess this time i'm on the right place ;p Well i need following: I have few forms (input fields) with requested informations, also i have other .php file which i'm calling to send a form. Now i need to know how can i do a check for those fields if they are empty or not. If they are, i need to STOP submiting the form (calling the other .php). Codes: Form: Code: [Select] <form name="f1" form method="post" action="posalji.php"/>Field: Code: [Select] <input type="text" name="hp1" size="20"/>Submit: Code: [Select] <input name="f1" type="image" src="registruj.png" onclick="if(f1.hp1.value.length==0) alert('Error: field can't be empty'); else f1.submit(); if(f1.hp2.value.length==0) alert('Error: field can't be empty'); else f1.submit();"/>There are more than one field, that's why you can see more errors in submit. Well all i need is "die" or "stop" calling the "posalji.php" from action above. Sry 4 poor english. Hello there, My current song request form process looks like: <?php if(isset($_POST['submit'])) { $to = 'address@website.com' ; $name = trim($_POST['name']); $message = trim($_POST['message']); $artist = trim($_POST['artist']); $song = trim($_POST['song']); $subject="Name:$name - Message:$message - Artist:$artist - Song:$song"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table> <tr><td>Name</td><td>".$_POST['name']."</td></tr> <tr><td>Message</td><td>".$_POST['message']."</td></tr> <tr><td>Artist</td><td>".$_POST['artist']."</td></tr> <tr><td>Song</td><td>".$_POST['song']."</td></tr> </tr></table>" ; mail($to, $subject, $message, $headers); header('Location: song-requests-success.php'); } ?> I'm currently using Javascript for blank validation, however, people seem to be getting through it somehow. I'm looking to implement PHP checkers that will output back to the request form with something like: Name field blank. Would this method work? $name = trim($_POST['name']); $artist = trim($_POST['artist']); $song = trim($_POST['song']); if(empty($name)){ $name1 .= "<br>Name is empty."; } if(empty($artist)){ $artist1 .= "<br>Artist is empty."; } if(empty($song)){ $song1 .= "<br>Song is empty."; } On form: <?php if(!empty($name)){ echo "".($name1).""; } ?> <?php if(!empty($artist)){ echo "".($artist1).""; } ?> <?php if(!empty($song)){ echo "".($song1).""; } ?> Would recalling the trim's be nessessary as they have already been specified for the email title. Would this need to be implemented into 'isset'. Many thanks. I am building a system where people are able to choose a food menu, they can modify each dish if needed and then say how many of each item they need for the order. So when they pick the breakfast menu, it selects all starters, mains and desserts. Should something need to be edited (sausages changed to vegitarian sausages) the user should be able to overtype what has been populated from the select statement) When the form is submitted, the order needs to be linked to the current job which is in a field ssm_job.job_id but the changes to the menu items need to be stored somewhere for the current order only. This obviously needs to be accessile later so further changes can be made if needed. I am not sure of the best way to go about this as i am trying not to save every item in another database (just trying to be tidy) Any advise on this would be greatly appreciated. I have had help on this project in relation to an sql and the background can be found below, the help has been amazing but as this is a very different question i thought i would start a new thread.
Kind Regards Hello everybody,
i try to check if the unique field inventar exists or not before i insert new record.
if the inventar exits the user should get error message.
but i dont know how to do this.
thank you very much for your help.
Rafal
here is my code
<?php include("123.php"); $inventar = $link1->real_escape_string($_POST["inp_inventar"]); $product = $link1->real_escape_string($_POST["inp_product"]); $price = $link1->real_escape_string($_POST["inp_price"]); $link1 = new mysqli("$hoster", "$nameuser", "$password", "$basedata") or die ("Connection Error!"); error_reporting (0); $check_inventar = mysqli_query($link1, "SELECT inventar FROM products WHERE inventar='$inventar'"); $check_inventar_num = mysqli_num_rows($check_inventar); if (isset($_POST['inp_submit']) AND $check_inventar_num = 0) { $query1 = "INSERT INTO products (inventar, product, price) VALUES ('$inventar', '$product', '$price')"; $result1 = $link1->query($query1) or die("Database Error!"); if ($result1 == true) { header ( 'Location:insert.php' ); } } else { echo "there is already product with same inventar id!"; } mysqli_close($link1); ?> Now this one is a bit of a shit head. I am using a really comprehensive class i found on on the web for upload / re-size / crop but i want to be able to override it's error handling and i am not good enough to start modifying the code in the class with out fucking it up. Firstly i will show you how i have invoked the class. Code: [Select] if( isset($_FILES['image'] ) ) { //Class includes include("../scrips/php/cms/database.insert.class.php"); include ("../scrips/php/cms/img.upload.resize.crop.class.php.php"); //----------|Start: upload, resize & save $your_image = new _image; //----------| Upload orginal image $your_image->uploadTo = 'uploads/'; $upload = $your_image->upload($_FILES['image']); //----------| Resize and upload small thumbnail $your_image->newPath = 'thums/'; $your_image->newWidth = 50; $your_image->newHeight = 50; $resized = $your_image->resize(); //----------| Resize and upload medium thumbnail $your_image->newPath = 'thums2/'; $your_image->newWidth = 100; $your_image->newHeight = 100; $resized = $your_image->resize(); //----------| Getting the image name to insert into the database futher on in the code $name = $resized; $img_str = explode("/",$name); $final_img_name = $img_str['1']; echo "Article has been added!"; //----------------|end //----------------| Start database insert (class manipulation) $table = "blog_posts"; $title = "'".$_POST['ArticleTitle']."',"; $img = "'".$final_img_name."',"; $post = "'".$_POST['ArticleBody']."',"; $aurthor_id = "'1',"; $category_id = "'".$_POST['Category']."',"; $date_posted = "NOW()"; $values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted"); $fields = array('title,','img,','post,','aurthor_id,','category_id,','date_posted'); $obj= new DatabaseInsert; $obj->DatabaseConnectionRequire(); $obj->ArticleInsert($values,$fields,$table); //----------------|end } As you can see it's fairly basic. What i want to do is before it runs this script and starts including/invoking the class etc, i want to be able to check to see if there is a value been posted from a FILE FORM OBJECT and if there is to proceed with this script, alternatively i want it to execute another code which will handle it in regards to the concept of my page. A simple javascript alert with be ok providing it reloaded the page to it's default state. If any one can help me here i would appreciate it a lot. Thanks I have a form with a gender control made up of two radio buttons. If the user doesn't fill out this form, nothing gets submitted (i.e name='gender') in the $_POST array. So how ae you supposed to verify that the form field was left blank, and use that information to say display an error message on the form? Edited February 16 by SaranacLakeI have a register script, and I am wanting to make it so that if the username field contains, lets say "mod", "ass", and more, then it'll return an error and wont let them register. |