PHP - Forms Help - Confirmation Page & Sticky Checkbox Input
Here is my code below. What I’m having a problem with is trouble to find how to sticky my checkbox and get to the confirmation page after clicking the submit input. I also need on the confirmation page to list what fields are not filled in.
<head> <meta http-equiv="Content-Type"content="text/html; charset=utf-8' /> <title>Assignment 4</title> <style type="text/css" title="text/css" media="all"> </style> </head> <div align="center"> <img src="nba2k20cover.jpg" alt="nba2k20 cover" width="616" height="353" /> <br> <br> <?php include('header.php'); ?> <h4> Hosted by: Zang Thao</h4> <h5> You are required to complete every field to your best!</h5> <body> <?php $name = $_POST['name']; $comments = $_POST['comments']; $gender = $_POST['gender']; $email = $_POST['email']; $league = $_POST['league']; $submit = $_POST['submit']; $monthsarray = array("Month", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $days = range(1,31); $daysdefault = array ('Day'); $daysarray = array_merge($daysdefault, $days); $years = range(2002,1910); $yearsdefault = array ('Year'); $yearsarray = array_merge($yearsdefault, $years); ?> <form name ="fbForm" id="fbForm" action="<?php if(($errors = NULL) && ($_SERVER['REQUEST_METHOD'] == 'POST')) { echo "handle.php"; $submit = true; } else { echo "index.php"; } ?>" method="post"> <fieldset><legend>Fill out the registration form below:</legend> <?php if(($_POST['name'] == NULL) && ($_SERVER['REQUEST_METHOD'] == 'POST')) { echo "<b>Please enter a name!</b>"; } ?> <p><label>Name: <input type="text" name="name" size="20" maxlength="40" value="<?php echo $_POST['name']; ?>" /></label></p> <?php if($_POST['email'] == NULL) { echo "<b>Please enter your email!</b>"; } ?> <p><label>Email Address: <input type="text" name="email" size="40" maxlength="60" value="<?php echo $_POST['email']; ?>" /></label></p> <?php if($_POST['gender'] == NULL) { echo "<b>Please select your gender!</b>"; } ?> <p><label for="gender">Gender:</label><input type="radio" name="gender" value="M"<?php if($_POST['gender'] == "M") { echo "checked"; } ?> /> Male<input type="radio" name="gender" value="F" /> Female</label></p> <?php if($_POST['month'] == NULL) { echo "<b>Please enter a birthday!</b>"; } ?> <p><label>Birth Date: <select name="month"> <?php foreach ($monthsarray as $value) { if($_POST['month'] == $value) { $isselected = "selected"; } else { $isselected = ""; } echo "<option value='$value' $isselected>$value</option> \n"; } ?> </select> <select name="day"> <?php foreach ($daysarray as $value) { if($_POST['day'] == $value) { $isselected = "selected"; } else { $isselected = ""; } echo "<option value='$value' $isselected>$value</option> \n"; } ?> </select> <select name="year"> <?php foreach ($yearsarray as $value) { if($_POST['year'] == $value) { $isselected = "selected"; } else { $isselected = ""; } echo "<option value='$value' $isselected>$value</option> \n"; } ?> </select></label></p> <?php if($_POST['league'] == NULL) { echo "<b>Please select a league!</b>"; } ?> <p><label for="league">Choose your league:</label><input type="checkbox" name="league" value="A"<?php if($_POST['opt'] == "A") { echo "checked"; } ?> /> A <input type="checkbox" name="league" value="B" <?php if($_POST['opt'] == "B") { echo "checked"; } ?>/> B <input type="checkbox" name="league" value="C" <?php if($_POST['opt'] == "C") { echo "checked"; } ?>/> C <input type="checkbox" name="league" value="D" <?php if($_POST['opt'] == "D") { echo "checked"; } ?>/> D</p> <?php if($_POST['comments'] == NULL) { echo "<b>Write down your questions/concerns if you don't have any write N/A!</b>"; } ?> <p><label>Questions/Concerns: <textarea name="comments" rows="3" cols="40"><?php echo $_POST['comments']; ?></textarea></label></p> </fieldset> <?php if ($submit) { echo"<script>document.getElementById('fbForm').submit();</script> "; } ?> <p align="center"><input type="submit" name="submit" value="REGISTER!" /></p> </form> <?php include('footer.php'); ?> </body> </html>
Similar TutorialsI've been poking around online for about a day now trying to find a good way to do the following: I have an "order" I'm reading in from a MySQL database (not completely relevant, but just fyi). And, for this order there are a number of "parts" (automotive parts) that have been ordered. For each part there is data pertaining to the quantity of parts that have been ordered and the number of parts that have been allocated (based on our inventory) and then a third column that has the number of parts still in that order that are still to be allocated at a future date. Basically, I'm displaying this data in a form with each row having a checkbox to the far left. What I want to do is allow the user to check any number of check boxes. If a check box is checked the form should submit all of the input text boxes for that row (the user can update the quantities) that I talked about in the second paragraph for that "part" (each part is displayed in a row and has a checkbox). Unfortunately, most of the examples I found for checkboxes in a form submit a specific value (like a number of a letter). I need the form to submit the values that are in the textboxes. So basically, I'm thinking I need the page to update a PHP object whenever the value of a textbox is changed and then when the user clicks a button it will send the php object for each checked row through GET or POST. But, how would I get it to onchange update a PHP object (the PHP object would need to be a 2-D array where the first index allows you to select the part and the second index allows you to select which quantity you will change). I'm thinking I would need to call a script from the onchange like: onchange="somePHPfunction(partNumberIndex, whichQuantityI'mChanging, currentValueOfThatQuantity)" but of course that would require me to embed some php inside the onchange call since the partNumberIndex and whichQuantity are PHP variables.. Any ideas on how to do this sort of thing? Or any ideas on how to do this differently? I'm trying to avoid javascript because it would place a javascript constraint on the users. But, maybe there's no other way to do this sort of thing? Any help would be greatly appreciated! hi, I have a form in which some information is required but the username is optional however if it is left blank it says that username is taken please choose another one. how can I make it accept it if a username isn't entered? Code: [Select] <?php if (!isset($_SESSION)){ session_start(); } $fname=""; $lname=""; $username=""; $password=""; $reenterPassword=""; $address=""; $state=""; $city=""; $zip=""; $phone=""; $fax=""; $email =""; $re_enter_email =""; $payment = ""; $paypal_username=""; $ship_first_name=""; $ship_last_name=""; $ship_address=""; $ship_city=""; $ship_state=""; $ship_zip=""; $ship_email=""; $ship_re_email=""; $pet_name=""; $age=1; $breed=""; $pet_name2=""; $age2=1; $breed2=""; // Logout if(isset($_POST['logout'])){ unset($_SESSION['user']); } // Loading captcha file require_once('recaptchalib.php'); $privatekey = "6LdxwsoSAAAAAO4CWYDjkrGQsf5GXuIopJcC6SkE"; $publickey = "6LdxwsoSAAAAAFrZTLjBoDvLLjk9_NR_ubncL-24"; require_once("functions.php"); DatabaseConnection(); $state = $_POST['state']; $payment = $_POST['payment_Method']; $breed = $_POST['breed']; $ship_state=$_POST['Shipstate']; if((isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="Log in") || $_SESSION['user']){ if(!$_SESSION['user']){ $login_username = isset($_REQUEST["username"])?$_REQUEST["username"]:""; $login_password = isset($_REQUEST["password"])?$_REQUEST["password"]:""; $msg = array(); if ($login_username == "") $login_msg['username_empty'] = "Please enter your name"; if ($login_password == "") $login_msg['password_empty'] = "Please enter your password"; $query = "SELECT * FROM customers WHERE username = '$login_username' AND password = '".$login_password."'"; }else{ $customer_id = $_SESSION['user']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; } if (!$login_msg){ $login_process = true; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $row = mysql_fetch_object($result); $customer_id = $row->customer_id; $_SESSION['user'] = $customer_id; $fname = $row->fname; $lname = $row->lname; $username=$row->username; $address=$row->address; $state=$row->state; $city=$row->city; $zip=$row->zip; $phone=$row->phone; $fax=$row->fax; $email =$row->email; $payment = $row->payment_method; $paypal_username=$row->paypal_username; $ship_first_name=$row->ship_first_name; $ship_last_name=$row->ship_last_name; $ship_address=$row->ship_address; $ship_city=$row->ship_city; $ship_state=$row->ship_state; $ship_zip=$row->ship_zip; $ship_email=$row->ship_email; $pet_name=$row->pet_name; $age=$row->age; $age_month=$row->age_month; $breed=$row->breed; $pet_name2=$row->pet_name2; $age2=$row->age2; $age_month2=$row->age_month2; $breed2=$row->breed2; }else{ $login_msg['login_fail'] = "Username, password combination is not valid."; } } } if(isset($_REQUEST["submit"]) && $_REQUEST["submit"]=="submit"){ $msg=array(); $fname=isset($_REQUEST["fname"])?$_REQUEST["fname"]:""; $lname=isset($_REQUEST["lname"])?$_REQUEST["lname"]:""; $username=isset($_REQUEST["lname"])?$_REQUEST["username"]:""; $password=isset($_REQUEST["lname"])?$_REQUEST["password"]:""; $reenterPassword=isset($_REQUEST["lname"])?$_REQUEST["reenterPassword"]:""; $address=isset($_REQUEST["address"])?$_REQUEST["address"]:""; $state=isset($_REQUEST["state"])?$_REQUEST["state"]:""; $city=isset($_REQUEST["city"])?$_REQUEST["city"]:""; $zip=isset($_REQUEST["zipcode"])?$_REQUEST["zipcode"]:""; $phone=isset($_REQUEST["phone"])?$_REQUEST["phone"]:""; $fax=isset($_REQUEST["fax"])?$_REQUEST["fax"]:""; $email =isset($_REQUEST["email"])?$_REQUEST["email"]:""; $re_enter_email =isset($_REQUEST["re_email"])?$_REQUEST["re_email"]:""; $re_enter_email= $email; $payment = isset($_POST['payment_Method'])?$_POST['payment_Method']:""; $paypal_username=isset($_REQUEST["PayPal_username"])?$_REQUEST["PayPal_username"]:""; $ship_first_name=isset($_REQUEST["Shipfname"])?$_REQUEST["Shipfname"]:""; $ship_last_name=isset($_REQUEST["Shiplname"])?$_REQUEST["Shiplname"]:""; $ship_address=isset($_REQUEST["Shipaddress"])?$_REQUEST["Shipaddress"]:""; $ship_city=isset($_REQUEST["Shipcity"])?$_REQUEST["Shipcity"]:""; $ship_state=isset($_REQUEST["Shipstate"])?$_REQUEST["Shipstate"]:""; $ship_zip=isset($_REQUEST["Shipzipcode"])?$_REQUEST["Shipzipcode"]:""; $ship_email=isset($_REQUEST["Shipemail"])?$_REQUEST["Shipemail"]:""; $ship_re_email=$ship_email; $pet_name=isset($_REQUEST["petName"])?$_REQUEST["petName"]:""; $age=isset($_REQUEST["age"])?$_REQUEST["age"]:''; $age=isset($_REQUEST["age_month"])?$_REQUEST["age_month"]:1; $breed=isset($_REQUEST["breed"])?$_REQUEST["breed"]:""; $nutritional_needs=isset($_REQUEST["nutritionalNeeds"])?$_REQUEST["nutritionalNeeds"]:""; $special_instructions=isset($_REQUEST["specialInstructions"])?$_REQUEST["specialInstructions"]:""; $pet_name2=isset($_REQUEST["petName2"])?$_REQUEST["petName2"]:""; $age2=isset($_REQUEST["age2"])?$_REQUEST["age2"]:""; $age2=isset($_REQUEST["age_month2"])?$_REQUEST["age_month2"]:1; $breed2=isset($_REQUEST["breed2"])?$_REQUEST["breed2"]:""; $nutritional_needs2=isset($_REQUEST["nutritionalNeeds2"])?$_REQUEST["nutritionalNeeds2"]:""; $special_instructions2=isset($_REQUEST["specialInstructions2"])?$_REQUEST["specialInstructions2"]:""; // Products information $product_name=isset($_REQUEST["productname"])?$_REQUEST["productname"]:""; $quantity=isset($_REQUEST["quantity"])?$_REQUEST["quantity"]:0; $price=isset($_REQUEST["price"])?$_REQUEST["price"]:0; $quantity_diff=isset($_REQUEST["quantity_diff"])?$_REQUEST["quantity_diff"]:0; $price_diff=isset($_REQUEST["price_diff"])?$_REQUEST["price_diff"]:0; $sales_tax=isset($_REQUEST["salestax"])?$_REQUEST["salestax"]:0; $subtotal=isset($_REQUEST["subtotal"])?$_REQUEST["subtotal"]:0; $shipping_cost=isset($_REQUEST["shippingcost"])?$_REQUEST["shippingcost"]:0; $total=isset($_REQUEST["total"])?$_REQUEST["total"]:0; // check for login if(isset($_POST['customer_id'])){ $customer_id = $_POST['customer_id']; $query = "SELECT * FROM customers WHERE customer_id='$customer_id'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ $login_process = true; $_SESSION['user'] = $customer_id; $row = mysql_fetch_object($result); $fname = $row->fname; $lname = $row->lname; $username=$row->username; } } // Is username taken ? if(!$login_process){ $query = "SELECT * FROM customers WHERE username = '$username'"; $result = mysql_query($query) or die("Database error: " . mysql_error()); if (mysql_num_rows($result) > 0){ array_push($msg,"This username is already taken, please choose another one."); } } if($fname==""){ array_push($msg,"Please Enter First Name."); } if($lname==""){ array_push($msg,"Please Enter Last Name."); } /* if($username==""){ array_push($msg,"Please Enter User Name."); } if(!$login_process){ if($password==""){ array_push($msg,"Please Enter Password."); } if($reenterPassword==""){ array_push($msg,"Please Enter Re-Enter Password."); } if($reenterPassword!=$password){ array_push($msg,"Both passwords does not match."); } }*/ if($address==""){ array_push($msg,"Please Enter Address."); } if($city==""){ array_push($msg,"Please Enter City."); } if($state=="Please choose a state"){ array_push($msg,"Please Select State."); } if($zip==""){ array_push($msg,"Please Enter Zip."); } else { if(!is_numeric($zip)){ array_push($msg,"Please Enter Digits In Zip."); } } if($phone==""){ array_push($msg,"Please Enter Phone."); } else { if(!is_numeric($phone)){ array_push($msg,"Please Enter Digits In Phone."); } } if($email==""){ array_push($msg,"Please Enter Email."); } if($payment==""){ //array_push($msg,"Please Select Payment Method."); } if($paypal_username==""){ // array_push($msg,"Please Enter Paypal User Name."); } if($ship_first_name==""){ array_push($msg,"Please Enter Shipping First Name."); } if($ship_last_name==""){ array_push($msg,"Please Enter Shipping Last Name."); } if($ship_address==""){ array_push($msg,"Please Enter Shipping Address."); } if($ship_city==""){ array_push($msg,"Please Enter Shipping City."); } if($ship_state==""){ array_push($msg,"Please Select Shipping State."); } if($ship_zip==""){ array_push($msg,"Please Enter Shipping Zip."); } else { if(!is_numeric($ship_zip)){ array_push($msg,"Please Enter Digits In Shipping Zip."); } } if($ship_email==""){ // array_push($msg,"Please Enter Shipping Email."); } // Check Captcha $resp = recaptcha_check_answer ($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"]); if (!$resp->is_valid) { array_push($msg,"Wrong Captcha, please try again."); } // Insert customer if($login_process){ $sql0 = "UPDATE customers SET address='$address',city='$city', state='$state', zip='$zip', phone='$phone', fax='$fax', email='$email', re_enter_email='$re_enter_email', ship_first_name='$ship_first_name', ship_last_name='$ship_last_name', ship_address='$ship_address', ship_city='$ship_city', ship_state='$ship_state', ship_zip='$ship_zip', ship_email='$ship_email', ship_re_enter_email='$ship_re_email', pet_name='$pet_name', age='$age', breed='$breed', pet_name2='$pet_name2', age2='$age2', breed2='$breed2', age_month='$age_month', age_month2='$age_month2' WHERE customer_id='$customer_id'"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = $customer_id; } }else{ $sql0="INSERT INTO customers (fname, lname,username,password, address, city, state, zip, phone, fax, email, re_enter_email, ship_first_name, ship_last_name, ship_address, ship_city, ship_state, ship_zip, ship_email, ship_re_enter_email , pet_name, age, breed, pet_name2, age2, breed2, age_month, age_month2) VALUES ('$fname', '$lname','$username','$password', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$pet_name2', '$age2', '$breed2', '$age_month', '$age_month2')"; if(count($msg) == 0){ $r= mysql_query($sql0) or die("Query Error : " . mysql_error()); $customer = mysql_insert_id(); } } // Insert Order $sql1="INSERT INTO orders (product_name, customer, quantity, price, sales_tax, subtotal, shipping_cost, total, nutritional_needs, special_instructions, nutritional_needs2, special_instructions2) VALUES ('$product_name', '$customer', '$quantity_diff', '$price_diff', '$sales_tax', '$subtotal', '$shipping_cost', '$total', '$nutritional_needs', '$special_instructions', '$nutritional_needs2', '$special_instructions2')"; if(count($msg) == 0){ $m= mysql_query($sql1) or die("Query Error : " . mysql_error()); } } ?> Any help would br GREAT! This Post is about Sticky Forms and How to get them working. I would like to record the users input after processing it. I have the processing page redirecting back to the form page. I have been trying and trying and trying some more to re-display the users input, so they don't hav eto keep entering the same crap ova & ova. I would imagine this must be done using sessions given I am not using PHP Self fuction.. Here's what I have that does not work at all :-) This first code is on the process page. Code: [Select] <?php ob_start(); session_start(); $itemDescription=$_POST['itemDescription']; $itemPrice=$_POST['itemPrice']; $itemQty=$_POST['itemQty']; $bidderId=$_POST['bidderId']; $totalPrice=$_POST['totalPrice']; mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); if (isset($bidderId)) { $totalPrice=$itemQty * $itemPrice; mysql_query("INSERT INTO transactions (itemDescription, itemPrice, itemQty, bidderId, totalPrice) VALUES('$itemDescription', '$itemPrice', '$itemQty', '$bidderId', '$totalPrice')") or die(mysql_error()); $_SESSION['itemDescription']='$itemDescription'; header("Location: attendance.php"); exit(); } else echo "<font face= \"calibri\" size= \"3\" color= \"red\">You have left a field blank, please press your browsers back button. </font>"; exit(); ob_end_flush(); ?> Now How do I display the users input back to the form? Code: [Select] <?php session_start(); $itemDescription = ""; //item description, default as blank ?> <form action="record_trans.php" method="post"> <font face= "calibri" size= "4"> <table> <tr> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value="<?php echo $itemDescription;?>"></td> </tr> <tr> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value="<?php echo $itemPrice;?>"> </td> </tr> </tr> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "bidderId" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <br/> <center><input type="submit" name="submit" value= "Save & Cont." " /></center> <center><input type="reset" value="Reset Form"></center> </form></font> [code] ALL SUGGESTIONS WELCOME- Before you leave give me ur take(if you have even a faint idea:-) Thanks Guys! Hi Guys, I am attempting to create a program for a local auction house. I arrived at a stand still on a certain issue which is creating a sticky form. On the "enter auction details page" the user will be entering data as the auction is in session. 1. item Description 2. Item Price 3. Bidders Id 4. Qty Of course it would be repetitive to require the user to keep entering the same data for every bidder, so I want to stick the obvious fields which are "item description" & "Item Price" as these don't change until a new item comes up for sale. As of know I am processing the input on a separate page which records all input to the database with a redirect back to the "enter auction details page". I have tried many times to get the item description and item price fields to stick. These would need to change as the user moves onto the next item in which the description and price would change as well. Here is my current code for this part: Code: [Select] <?php session_start(); $field_itemDescription = ""; //iyem description, default as blank if (isset($_SESSION['itemDescription'])) $itemDescription = $_SESSION['itemDescription']; ?> <form action="record_trans.php" method="post"> <font face= "calibri" size= "4"> <table> <tr> <td><b>Item Description:</b></td> <td><input type= "text" name= "itemDescription" size= "30" value="<?php echo $itemDescription;?>"></td> </tr> <tr> <td><b>Item Price:</b></td> <td><input type= "text" name= "itemPrice" size= "5" value="<?php echo $itemPrice;?>"> </td> </tr> </tr> <td><b>Winning Bidders:</b></td> <td><input type="text" name= "bidderId" size= "5" /> </td> </tr> <tr> <td><b>How many deals?:</b></td> <td><input type="text" name= "itemQty" size= "3" value= "1" /></td> </tr> </table> <center><input type="submit" name="submit" value= "Save & Cont." " /></center> </form></font> I hope I can explain what is happening. I have created two forms in PHP. The first 'almost' works, i.e. it shows the data. But I have two problems - 1) the second pulldown menu is always empty and 2) $value from the first pulldown menu ALWAYS equals the last entry thus the last 'if' in the function subdomains ($domains) is always called (but still empty). The code may explain this better than me:
<!DOCTYPE html> <html> <body> <!-- processDomains.php is this file - it calls itself (for testing purposes so I can see what is happening) --> <form action="processDomains.php" method="post"> <?php // create the domains array (there are actually several entries in the array but I cut it down for testing) $domains = array (1 => 'Decommission', 'Migration'); echo "Select Domain:"; echo "<br>"; // Make the domain pull-down menu - this displays correctly echo '<select name="domain">'; foreach ($domains as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; // input doesn't matter what is 'submitted', always goes to last $value echo '<input type="submit" name="submit" value="Submit">'; // call function subdomains subdomains ($value); function subdomains ($domains) { // define values for each array - each array contains available choices for the subdomain pulldown menu $migration = array (1 => 'Application Migration', 'Application Patch', 'Application Upgrade'); $decommission = array (1 => 'Applications', 'Servers', 'Storage'); if ($domains === 'Migration') { echo "Select subdomain:"; echo "<br>"; // Make the Migration pull-down menu echo '<select name="migration">'; foreach ($migration as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; } else if ($domains === 'Decommission') { /* === * since 'Decommission' is the last entry in the 'Domains' pulldown list, $value ALWAYS equals * 'Decommission' and $domains equals $value. So this menu SHOULD work but is always * empty. Thus, two problems - the pulldown menu is always empty and $value isn't based * upon user input. */ echo "Select subdomain:"; // this prints so I know I'm in 'Decommission (I eliminated the echo "$domain" to show I'm always coming here)' echo "<br>"; // Make the 'Decommission' pull-down menu echo '<select name="decommission">'; foreach ($decommission as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; echo '<input type="submit" name="submit" value="Submit">' ) // end of 'if-else' } // end of function 'subdomain' ?> </form> </body> </html>Let me say thank you in advance and I appreciate the help! I know I'm doing something (or more than one thing) wrong and I hope someone can tell me what it is. Best Regards! Edited by mac_gyver, 19 January 2015 - 09:37 PM. code tags around posted code please Hello all, Im making a Quote Request Form for my dads company. So first they have the actual form then they click submit and it going to a confirmation page so they can review their information, at the confirmation page i want the end user to be able to click confirm and it sends the form to my e-mail. and if they made a mistake to be able to click button saying go back and they just change the information. I tried to set it up that way but when i click submit, it says it submitted and i got the e-mail but none of the info was there, and the back button kept me on the confirmation page but erased all the data. I am fairly new to PHP and am having an issue with getting my form to redirect to a thank you page upon sending the form email. I currently have it set to echo a thank you message but it needs to be changed to ensure that we can track all form fills better. I have tried the header method but it doesn't work correctly based on how the website is designed. It seems like there should be an easy way without redesigning too much. Are there any other ways to accomplish this? Please let me know what I need to do in order to get the redirect to work. Good afternoon,
I was wondering if you could help me out with a few things. I have created a registration page and it stores the information into my database. A success page then appears with some of the details they entered as a confirmation page. Unfortunately I cannot get the information to appear on the page. I have included some code, any help would be greatly appreciated.
<?php Guys, quick one. Im writing a script for a form to post info into a MySql table. Now rather than just having a single row for input I'd like to have lets say 10 rows, so I can add 10 records to the database. What I'm pondering is 2 things: 1: can i just repeat Code: [Select] <input type="text" name="opponent" size="27" /> over and over, or is it going to need its own name each time for example; Code: [Select] <input type="text" name="opponent2" size="27" /> <input type="text" name="opponent3" size="27" /> 2: when it comes to the processing script is it more economical to have the forms input field named the same over and over (if it IS possible) and if not whats the most econimcal way to code my Code: [Select] $opp= $_POST['opponent']; $query="INSERT INTO fixtures (match_date, season, opponent) VALUES ('$date', '$season', '$opp',)"; Your help and comments are appreciated as always guys Tom Here's a question for all you great php programmers. What I want to do is use a variable username as the name of a select input of a form. I.E echo"<select name='$user'>"; Of course this code doesn't work though I feel sure that there must be a way to do this. Anyone know it? On all my forms, after I send an empty string to one field, it will stop accepting values when I resubmit. My code passes through the W3C validator Any ideas?? Hi, I have made a basic html site and it has two forms on it. I have the forms linking to a file called process.php. Basically i need to know what code to put in the php file in order for the forms to save whatever is entered in them to a txt file on my server or computer. Or any other easier way to do the same thing, save the content of two forms on my site. Hope i posted this in the right forum subject. Thanks very much for anyone that helps. Hi people, I really hope you guys can help me out today. I'm just a newbe at php and i'm having real trouble. Bassically all I want to do is have a user type in a company name in a html form. If what the user types in the form matches the company name in my php script i want the user to be sent to another page on my site. If what the user types in the form doesnt match the company name in my php script i want the user to be sent to a differnt page like an error page for example. this is my html form: Code: [Select] <form id="form1" name="form1" method="post" action="form_test.php"> <p>company name: <input type="text" name="company_name" id="company_name" /> </p> <p> <input type="submit" name="button" id="button" value="Submit" /> </p> </form> And this is the php code I'm trying to process the information on: Code: [Select] <?php $comp_name = abc; if(isset ($_POST["company_name"])){ if($_POST["company_name"] == $comp_name){ header("Location: http://www.hotmail.com"); exit(); } else{ header("Location: http://www.yahoo.com"); exit(); } } ?> The thing is i'm getting this error when i test it: Warning: Cannot modify header information - headers already sent by (output started at D:\Sites\killerphp.com\form_test.php:10) in D:\Sites\killerphp.com\form_test.php on line 17 Please can some one help me out, i'm sure this is just basic stuff but i just cant get it to work Cheers. Hi guys, I was wondering if it is possible to like a page on facebook through a checkbox, instead of using the FB like function/script. In other words; people fill out a form and can check the box if they like the page, such as: Code: [Select] <?php if (isset($_POST['form'])) { if (isset($_POST['facebook_checkbox'])) { //like page } else{ //don't like } } ?> <form action="<? $_SERVER['PHP_SELF'];?>" method="post"> <input type="checkbox" id="facebook_checkbox" name="facebook_checkbox" /> <input type="submit" name="form" /> Is there any possibility to do that? Thanks in advance. Ok here are two of my form codes: Basically I like to use if/elseif, can someone please explain to me how these two form here can combine together so it will only have one form but do two different function (create and modify form). Then after these form being edit or create - it will go to another different page which is the confirmation page using sessions. modify form code <?php require 'includes/application.php'; //Define $name = ""; $surname = ""; $add = ""; $dept= ""; $mobile = ""; if (!isset($_POST['goSubmit'])) { $q = "SELECT * FROM persons WHERE ID = $_GET[id]"; $result = mysql_query($q) or die (mysql_error()); $row = mysql_fetch_array($result); $name = $row['name']; $surname = $row['surname']; $address = $row['address']; $dept = $row['dept_id']; $mobile = $row['mobile']; } $errormsg = ""; if($name == "") $errormsg = $errormsg. "Name<br/ >"; if ($surname == "") $errormsg = $errormsg. "Surname Please <br/ >"; if ($mobile != "" && !is_numeric ($mobile)) $errormsg = $errormsg. "Mobile No? <br/ >"; if ($errormsg != "") echo "Please fill the blank info: <br/ > $errormsg"; else { $input_field = ""; foreach ($_POST as $key => $val) { if ($key != 'goSubmit') { $_SESSION[$key] = $val; } } header("Location: confirmPage.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=iso-8859-1" /> <title>Modify Document</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="center"> <table width="300" border="1"> <h1> Modifying A User </h1> <tr> <th scope="row">Name</th> <td><input type="text" name="name" value="<?php echo $name;?>" /></td> </tr> <tr> <th scope="row">Surname</th> <td> <input type="text" name="surname" value="<?php echo $surname; ?>" /></td> </tr> <tr> <th scope="row">Address</th> <td><input type="text" name="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <th scope="row">Department</th> <td> <select name="dept"> <option value="">Select..</option> <?php $data = mysql_query ("SELECT * FROM dept ORDER BY `id` DESC") or die (mysql_error()); echo $data; while($row_dept = mysql_fetch_array( $data )) { ?> <option value="<?php echo $row_dept['id'] ;?>" <?php if($row_dept['id']==$dept){echo ' selected="selected"';}?>> <?php echo $row_dept['dept_name'] ;?> </option> <?php } ?> </select> </td> </tr> <tr> <th scope="row">Mobile</th> <td><input type="text" name="mobile" value="<?php echo $mobile; ?>" /></td> </tr> </table> <br/> <a href="indexPage.php"> <input type="button" name="back" value="Back" /></a> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"> <input type="submit" name="goSubmit" value="Modify"/> </div> </form> </body> </html> create form page <?php require 'includes/application.php'; //Define $name = ""; $surname = ""; $address = ""; $dept= ""; $mobile = ""; // isset determine if a varaible is set if (isset($_POST['goSubmit'])) { $name = $_POST['name']; $surname = $_POST['surname']; $address = $_POST['address']; $dept = $_POST['dept']; $mobile = $_POST['mobile']; print_r($_POST); $errormsg = ""; if($name == "") $errormsg = $errormsg. "Name<br/ >"; if ($surname == "") $errormsg = $errormsg. "Surname Please <br/ >"; if ($mobile != "" && !is_numeric ($mobile)) $errormsg = $errormsg. "Mobile No? <br/ >"; if ($errormsg != "") echo "Please fill the blank info: <br/ > $errormsg"; else { $input_field = ""; foreach ($_POST as $key => $val) { if ($key != 'goSubmit') { $_SESSION[$key] = $val; } } header("Location: confirmPage.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=iso-8859-1" /> <title>Modify Document</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div align="center"> <table width="300" border="1"> <h1> Modifying A User </h1> <tr> <th scope="row">Name</th> <td><input type="text" name="name" value="<?php echo $name;?>" /></td> </tr> <tr> <th scope="row">Surname</th> <td> <input type="text" name="surname" value="<?php echo $surname; ?>" /></td> </tr> <tr> <th scope="row">Address</th> <td><input type="text" name="address" value="<?php echo $address; ?>" /></td> </tr> <tr> <th scope="row">Department</th> <td> <select name="dept"> <option value="">Select..</option> <?php $data = mysql_query ("SELECT * FROM dept ORDER BY `id` DESC") or die (mysql_error()); echo $data; while($row_dept = mysql_fetch_array( $data )) { ?> <option value="<?php echo $row_dept['id'] ;?>" <?php if($row_dept['id']==$dept){echo ' selected="selected"';}?>> <?php echo $row_dept['dept_name'] ;?> </option> <?php } ?> </select> </td> </tr> <tr> <th scope="row">Mobile</th> <td><input type="text" name="mobile" value="<?php echo $mobile; ?>" /></td> </tr> </table> <br/> <a href="indexPage.php"> <input type="button" name="back" value="Back" /></a> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>"> <input type="submit" name="goSubmit" value="Modify"/> </div> </form> </body> </html> I was thinking something like these condition to do the forms but I am not exactly sure... - But after this page another confirmation page will appear once the button submitted is click. if (isset($_GET['id']) == $id) { //do the modify query //display the modify form } else if (isset ($_GET ['id'] == NULL) { //display the form where user can fill up the form } OR, can I do like this instead: if (isset ($_GET['id'])) { $_SESSION ['page'] = 'modify'; //perform the modify form } else if (isset($_GET['id'])) { $_SESSION ['page'] = 'create'; //perform the create form } Any inputs would be appreciated... Hi, I've tried to follow a couple tuts on multi-page forms using php. The reason I'm doing it is that I'd like to create a mock-job application form for my students at school. This would be too long to have on one page. Anyway, I've created the most simple form I could think of and was hoping someone could help me out and show me how to get the info from page 1 to 2, then the info from pages 1 and 2 to 3, and then submit the info from pages 1, 2 and 3 to the database. Page 1 asks for firstname, page 2 asks for lastname, and page 3 asks for email address. The fourth page is the one that processes the form. Page 1: (app_form_1.php) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_2"> Firstname: <label> <input type="text" name="firstname" id="firstname" /> </label> </form> <p> <label> <input type="submit" name="Continue" id="Continue" value="Continue" /> </label> Page 2 (app_form_2.php) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_3"> Lastname: <label> <input type="text" name="firstname" id="firstname" /> </label> </form> <p> <label> <input type="submit" name="Continue" id="Continue" value="Continue" /> </label> Page3 ( app_form_3.php ) Code: [Select] <form id="form1" name="form1" method="post" action="app_form_process"> Email address: <label> <input type="text" name="emailaddress" id="emailaddress" /> </label> </form> <p> <label> <input type="submit" name="submit" id="Submit" value="Submit" /> </label> Page 4 (app_form_process.php ) Code: [Select] <?php global $_POST; $firstname = $_POST["firstname"] ; $lastname = $_POST["lastname"]; $emailaddress = $_POST["emailaddress"]; //**********************SEND TO DATABASE**************************** //MySQL Database Connect include 'mysql_connect.php'; $query = "INSERT INTO application_form (firstname, lastname, emailaddress)" . "VALUES ('$firstname', '$lastname', '$emailaddress')"; //if($query){echo 'data has been placed'} mysql_query($query) or die(mysql_error()); ?> Any help is much appreciated. Thanks, Dave First, I will select checkbox then click generate report then it displays the items with download link Then i click download link to download the selected checkbox values in pdf I want to download the selected checkbox items by clicking download link Now i am getting all check box items in the pdf download How to download only the selected check box items Code: [Select] <?php session_start(); $_SESSION['pidd'] = 2; $sessvar = $_SESSION['pidd']; ?> <!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> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="css/style.css" /> <style type="text/css" media="print"> DIV#noprint{visibility:hidden;} INPUT#printbutt{visibility:hidden;} #downloadlink{visibility:hidden;} </style> <script type="text/javascript"> function gen() { var st1=document.getElementById("ckbox1").checked; var st2=document.getElementById("ckbox2").checked; var st3=document.getElementById("ckbox3").checked; var st4=document.getElementById("ckbox4").checked; if(st1 == true) { document.getElementById('g1').style.display = 'block'; } if(st2 == true) { document.getElementById('g2').style.display = 'block'; } if(st3 == true) { document.getElementById('g3').style.display = 'block'; } if(st4 == true) { document.getElementById('g4').style.display = 'block'; } document.getElementById('p_info').style.display = 'none'; document.getElementById('histree').style.display = 'none'; document.getElementById('insurence').style.display = 'none'; document.getElementById('billin').style.display = 'none'; } function showuser() { document.getElementById('g1').style.display = 'none'; document.getElementById('g2').style.display = 'none'; document.getElementById('g3').style.display = 'none'; document.getElementById('g4').style.display = 'none'; var str1=document.getElementById("ckbox1").checked; var str2=document.getElementById("ckbox2").checked; var str3=document.getElementById("ckbox3").checked; var str4=document.getElementById("ckbox4").checked; if(str1 == true) { document.getElementById('p_info').style.display = 'block'; } else document.getElementById('p_info').style.display = 'none'; if(str2 == true) { document.getElementById('histree').style.display = 'block'; } else document.getElementById('histree').style.display = 'none'; if(str3 == true) { document.getElementById('insurence').style.display = 'block'; } else document.getElementById('insurence').style.display = 'none'; if(str4 == true) { document.getElementById('billin').style.display = 'block'; } else document.getElementById('billin').style.display = 'none'; } function checkByParent(aId, aChecked) { var collection = document.getElementById(aId).getElementsByTagName('INPUT'); for (var x=0; x<collection.length; x++) { if (collection[x].type.toUpperCase()=='CHECKBOX') collection[x].checked = aChecked; } } </script> </head> <body> <div id="main_content"> <div id="left"> <div id="noprint"> <h4>Patient Report</h4> <a id="check_all" href="#" style="text-decoration:none" onClick="checkByParent('checkboxes', true); return false;">check all</a> <a id="uncheckall" href="#" style="text-decoration:none" onClick="checkByParent('checkboxes', false); return false;">uncheck all</a> <br> <br> <form method="post" name="myform" action=""> <div id="checkboxes"> <div id="cb_id1"> <input id="ckbox1" name="cbox1" type="checkbox" <? if(isset($_REQUEST['cbox1'])) echo 'checked="checked"' ; ?> value="p_info" /> Patient Info </div> <div id="cb_id2"> <input id="ckbox2" name="cbox2" type="checkbox" <?php if(isset($_REQUEST['cbox2'])) echo 'checked="checked"' ; ?> value="histree" /> History </div> <div id="cb_id3"> <input id="ckbox3" name="cbox3" type="checkbox" <?php if(isset($_REQUEST['cbox3'])) echo 'checked="checked"' ; ?> value="insurance" /> Insurence </div> <div id="cb_id4"> <input id="ckbox4" name="cbox4" type="checkbox" <?php if(isset($_REQUEST['cbox4'])) echo 'checked="checked"' ; ?> value="billin" /> Billing </div> </div> <!--checkboxes div --> <br> <input id="vuprint" name="view" type="button" value="View" onClick="showuser();"> <hr/> <label for="docs"> Documents:<br> <br> </label> <input name="sub" type="button" value="Generate report" onclick="gen();"> <hr/> </form> <input id="printbutt" name="prt" type="button" value="Print" onClick="javascript:window.print();"> </div> <!--No print --> </div> <!--Left div --> <div id="side"> <div id="p_info"> <?php require("db_conn.php"); $pinfo = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='".$sessvar."' "); while($fet = mysqli_fetch_array($pinfo)) { echo "<h4>Patient Info</h4>"; echo "<b>Name: </b>" . $fet["P_Fname"] . " " . $fet["P_Lname"]. "<br>"; echo "<b>Dob:</b> " . date("d-m-Y",strtotime($fet["P_Dob"]))."<br>"; echo "<b>Age:</b> " . $fet["P_Age"]."<br>"; echo "<b>Gender:</b> " . $fet["P_Gender"]."<br>"; echo "<b>Marital Status:</b> " . $fet["P_Mstatus"]."<br>"; echo "<b>Blood: </b>" . $fet["P_Blood"]."<br>"; echo "<b>Height: </b>" . $fet["P_Height"] . $fet["P_Hval"]."<br>"; echo "<b>Weight: </b>" . $fet["P_Weight"] . $fet["P_Wval"]; } ?> </div> <div id="histree"> <?php $his = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='".$sessvar."' "); while($hisrow = mysqli_fetch_array($his,MYSQLI_ASSOC)) { echo "<h4>Patient Histroy</h4>"; echo "<b>P_Idate: </b>" . date("d-m-Y",strtotime($hisrow["P_Idate"]))."<br>"; echo "<b>P_Edate: </b>" . date("d-m-Y",strtotime($hisrow["P_Edate"]))."<br>"; echo "<b>D_Ddate: </b>" . date("d-m-Y",strtotime($hisrow["D_Ddate"])); } ?> </div> <!-- Insurence --> <div id="insurence"> <?php $insu = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='".$sessvar."' "); while($insrow = mysqli_fetch_array($insu,MYSQLI_ASSOC)) { ?> <?php echo "<h4>Insurence</h4>"; echo "<b>P_Isname: </b>" . $insrow["P_Isname"]."<br>"; // echo $insow[""]; } ?> </div> <div id="billin"> <?php $bilrow = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='1' "); while($bill = mysqli_fetch_array($bilrow,MYSQLI_ASSOC)) { ?> <?php echo "<h4>Billing</h4>"; echo "<b>P_Fbill: </b>" . $bill["P_Fbill"]."<br>"; echo "<b>Fees: </b>" . $bill["fees"]; } ?> </div> </div> <!--/side div --> <div id="generatereport"> <div id="g1" style="display:none; clear:both;"> <label for="Gen_reports">Generaterd reports</label> <br /> <br /> <?php $pinfo = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='1' "); while($fet = mysqli_fetch_array($pinfo,MYSQLI_ASSOC)) { $new_dob = date("d-m-Y",strtotime($fet["P_Dob"])); ?> <?php echo "<h4>Patient Info</h4>"; echo "<b>Patient Id:</b> ". $fet["P_Id"]."<br>"; echo "<b>Name:</b> " . $fet["P_Fname"] . " " . $fet["P_Lname"]."<br>"; echo "<b>Dob:</b> " . $new_dob ."<br>"; echo "<b>Age:</b> " .$fet["P_Age"]."<br>"; echo "<b>Gender:</b> " . $fet["P_Gender"]."<br>"; echo "<b>Marital Status:</b> " . $fet["P_Mstatus"]. "<br>"; echo "<b>Blood:</b> " . $fet["P_Blood"] . "<br>"; echo "<b>Height:</b> " . $fet["P_Height"] . $fet["P_Hval"]. "<br>"; echo "<b>Weight:</b> " . $fet["P_Weight"] . $fet["P_Wval"]. "<br>"; } echo "*************************************************************************************************************************"; ?> </div> <div id="g2" style="display:none"> <?php $his = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='1' "); while($secrow = mysqli_fetch_array($his,MYSQLI_ASSOC)) { echo "<h4>Patient Histroy</h4>"; echo "<b>P_Idate:</b> " . date("d-m-Y",strtotime($secrow["P_Idate"])) ."<br>"; echo "<b>P_Edate:</b> " . date("d-m-Y",strtotime($secrow["P_Edate"])) ."<br>"; echo "<b>D_Ddate:</b> " . date("d-m-Y",strtotime($secrow["D_Ddate"])) ."<br>"; } echo "*************************************************************************************************************************"; ?> </div> <div id="g3" style="display:none"> <?php $insu = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='1' "); while($insrow = mysqli_fetch_array($insu,MYSQLI_ASSOC)) { echo "<h4>Insurence</h4>"; echo "<b>P_Isname:</b>" . $insrow["P_Isname"]."<br>"; } echo "*************************************************************************************************************************"; ?> </div> <div id="g4" style="display:none"> <?php $bilrow = mysqli_query($mysqli,"SELECT * FROM patient_datas WHERE P_Id='1' "); while($bill = mysqli_fetch_array($bilrow,MYSQLI_ASSOC)) { echo "<h4>Billing</h4>"; echo "<b>P_Fbill:</b> " . $bill["P_Fbill"]."<br>"; echo "<b>Fees:</b> " . $bill["fees"]; } ?> </div> <?php $infochk = 'p_info'; $hischk = 'histree'; $insuchk = 'insurance'; $billchk = 'billin'; ?> <a id="downloadlink" href="download_pdf2.php?info=<?php if(isset($infochk)) echo $infochk; ?>&hist=<?php if(isset($hischk)) echo $hischk; ?>&insu=<?php if(isset($insuchk)) echo $insuchk; ?>&billin=<?php if(isset($billchk)) echo $billchk; ?>">Download</a> </div> <!--generate report --> </div> <!--/main_coontent --> </body> </html> database.php Hi guys, basically my problem is I have a jquery pop out window that holds a login form using the "require_once" function but when I enter my login details and send them, if there is another another form on the page e.g contact form it will send that form aswell so it will come up for the errors for the register form because they are empty. can anyone tell me how to stop this from happening? Hey guys, im new to php and have become stuck with having more than one html form/submit that will relays to another piece of code to view something At the moment my first form works but once i submit my second form it relays back to the first form how can i prevent this so i can have many submit forms on one php page? Thanks Code: [Select] <?php $dbname = $_POST['dbname']; $tblname = $_POST['tblname']; checksubmit( $dbname); function checksubmit( $dbname){ if(isset($_POST['enter'])) { checkform( $dbname); } else { page1( $dbname); } } function checkform ($dbname){ if(empty($_POST['dbname'])){ echo 'fill out database name'; } else page2( $dbname ); } function page1( $dbname){ echo " <form method='post' action=''> <table> <tr> <td>Database name:</td><td><input type='text' name='dbname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='enter' value='enter' /></td> </tr> </table> </form> "; } function page2( $dbname ){ echo " <form method='post' action=''> <table> <tr> <td>Table Name:</td><td><input type='text' name='tblname' /></td> </tr><tr> <td colspan='2' align='right'><input type='submit' name='return' value='return' /></td> </tr> </table> </form> "; if(isset($_POST['return'])) { page3( $dbname ); } } function page3( $dbname ) { echo 'I want to make it here'; } ?> |