PHP - Submit Form -> Radio Buttons Left Unselected Don't Send
So I have created an online test .
I have the results from the form submitted to my email. It is working great but the only problem is that when a question is left unanswered, the radio button doesn't have a result. What i want it to do is when a question is left unanswered, the email should look like this (Question) 1_01: True 1_02: Unanswered 1_03: False 1_04: Unanswered 1_05: True Right now it looks like this: (Question) 1_01: True 1_03: False 1_05: True I can't make the radio button required because it is a timed test where you have to work fast, so unanswered questions are going to happen. How do I make it so that unanswered radio buttons submit the value "unanswered" in the E-mail? Similar TutorialsHi all, What I am trying to achieve is, I thought quite simple! Basically, a user signs up and chooses a package, form is submitted, details added to the database, email sent to customer, then I want to direct them to a paypal payment screen, this is where I am having issues! Is their any way in php to submit a form without user interaction? Here is my code for the form process page Code: [Select] <?php include('config.php'); require('scripts/class.phpmailer.php'); $package = $_POST['select1']; $name = $_POST['name']; $email = $_POST['email']; $password = md5($_POST['password']); $domain = $_POST['domain']; $a_username = $_POST['a_username']; $a_password = $_POST['a_password']; $query=mysql_query("INSERT INTO orders (package, name, email, password, domain, a_username, a_password) VALUES ('$package', '$name', '$email', '$password', '$domain', '$a_username', '$a_password')"); if (!$query) { echo "fail<br>"; echo mysql_error(); } else { $id = mysql_insert_id(); $query1=mysql_query("INSERT INTO customers (id, name, email, password) values ('$id', '$name', '$email', '$password')"); if (!$query1) { echo "fail<br>"; echo mysql_error(); } if($package=="Reseller Hosting") { //email stuff here - all works - just cutting it to keep the code short if(!$mail->Send()) { echo "Message could not be sent. <p>"; echo "Mailer Error: " . $mail->ErrorInfo; exit; } ?> <form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <input type="hidden" name="business" value="subscription@jollyhosting.com"> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="item_name" value="Jolly Hosting Reseller Packages"> <input type="hidden" name="no_shipping" value="1"> <!--1st month --> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="a3" value="3.00"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="t3" value="M"> <input type="hidden" name="src" value="1"> <input type="hidden" name="sra" value="1"> </form>'; <?php } //last } //end ?> Hello All,
I'm kinda new to PHP and web development and I seem to have a very wierd problem which is driving me nuts (for the last 2 days)...so I'd appreciate any and all help in getting it resolved.
Okay, so here's the problem:
In the code below, I used to have just the first statement below...which essentially accepted input as a textbox for a text field named qty_pkg (in the underlying MySQL table)...and that used to work just fine.
So then I decided to change the input type for that field to be a radio button, accepting one of two choices i.e. "UoM" or "Qty", and therefore I added the remainder of the code, whilst also commenting/remarking out the first statement.
What happens (when I added the radiobutton-related code) is that control no longer goes into the TRUE portion/logic of the "if ( !empty($_POST))" condition-check, but rather, it seems to go into the "ELSE/FALSE" portion of that conditional check. However, a record does get added to my table, even though I do not have an "INSERT INTO..." clause in the ELSE porition of that check. Also, what gets displayed on screen is as follows:
------------------------------------------------------------------------------------------------------------------------------------
Array()
There's something wrong somewhere!!!
Array()
------------------------------------------------------------------------------------------------------------------------------------
Now, if/when I comment/remark the radiobutton-related code, the "if ( !empty($_POST))" logic seems to work fine and the following is displayed on screen (which is what I expect):
------------------------------------------------------------------------------------------------------------------------------------
Array ( [datepicker] => 10/30/2014 [store_id] => 48 [new_store_name] => [item_id] => 5 [new_item_name] => [pkg_of] => 1 [price] => 1 [flyer_page] => 1 [limited_time_sale] => Array ( [0] => fri [1] => sat ) [nos_to_purchase] => 1 [create-and-add-more] => Create and Add More ) Notice: Undefined index: qty_pkg in /var/www/create.php on line 54 Array ( [0] => Array ( [item_id] => 5 [0] => 5 [item_name] => BD Cheese Strings [1] => BD Cheese Strings [section_id] => 7 [2] => 7 ) ) ------------------------------------------------------------------------------------------------------------------------------------ The other wierd thing is that if/when I now uncomment the first statement (which used to work just fine before) the "if ( !empty($_POST))" logic no longer seems to work the way it used to. Does/can someone see something wrong with my code somewhere? <!-- <?php echo standardInputField('Qty / Pkg', 'qty_pkg', $qty_pkg, $errors); ?> --> <div class="control-group"> <label class="control-label">Priced by:</label> <div class="priced-by-radio-container"> <div class="pb-radiobuttons-container"> <label class="indent-to-the-left"> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='UoM' $pb1> <span class='no-highlight'>Unit of Measure</span> </label> <label> <input class='priced-by-radiobutton' type='radio' name='qty_pkg' value='Qty' $pb2> <span class='no-highlight'>Quantity</span> </label> </div> </div> </div> <?php echo standardInputField('UoM Name/Pkg. Of:', 'pkg_of', $pkg_of, $errors); ?> <?php echo standardInputField('Price:', 'price', $price, $errors); ?> <?php echo standardInputField('Flyer Page #:', 'flyer_page', $flyer_page, $errors); ?> print_r($_POST); if ( !empty($_POST)) { // keep track of $_POST(ed) values by storing the entered values to memory variables $store_id = $_POST['store_id']; $item_id = $_POST['item_id']; $qty_pkg = $_POST['qty_pkg']; $pkg_of = $_POST['pkg_of']; ... ... $sql = "INSERT INTO shoplist (store_id,item_id,qty_pkg,pkg_of,price,flyer_page,limited_time_sale,flyer_date_start,nos_to_purchase,section_id,shopper1_buy_flag,shopper2_buy_flag,purchased_flag,purchase_later_flag,no_flag_set) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $q = $pdo->prepare($sql); $q->execute(array($store_id,$item_id,$qty_pkg,$pkg_of,$price,$flyer_page,$limited_time_sale,$flyerDateStart,$nos_to_purchase,$section_id,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_N,$initialize_flag_Y)); } else { echo "<br />There's something wrong somewhere!!!<br />"; print_r ($_POST); $qty_pkg = ''; $pkg_of = '';;Thanks. One submit button goes to my own login system.. the other goes to a billing system. I am having problems getting it to work probably because there are alot of if and else if statements. Or maybe I am just missing something. The problem is the line with blesta.. I take that if isset out and just start with if permission =1 then all is great but I need both of them to operate .. with one being sent to one place and the other to another one. the login file and my form has both input types ready to go within it.. I can declare the values I just need to know what I am doing wrong in the if statement. Code: [Select] <input type="image" name="blesta" id="BtnSubmit" src="images/cart.jpg" width="25" height="20" submit="Blesta"></td> <td><input name="login" type="image" class="vote" src="images/index19.jpg" submit="login"></td> Code: [Select] <? session_start(); $username = $_SESSION["username"]; ?> <html><body> <title>Login</title> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td class="poptop" height="10"><img src="password/images/spacer.gif" width="3" height="3"><img src="logo.png" border="0"></td> </tr> <tr> <td class="hrz_line"><img src="password/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td style="background: #ffffff; padding: 5px" valign="middle"><h1 style="margin-top: 0; margin-bottom: 0">Welcome<br><br> Newest User: <font style="FONT-FAMILY: Verdana; FONT- SIZE: 7pt"><?php $connect = mysql_connect("localhost", "username", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); $query = "SELECT * FROM users ORDER BY created DESC LIMIT 1"; $result = mysql_query($query, $connect) or die ("QUERY FAILED: " . mysql_error()); $row = mysql_fetch_array($result,MYSQL_ASSOC);?> <?echo $row[username]; ?></td></h1></font> </tr> <tr> <td class="hrz_line"><img src="password/images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td valign="top" style="padding: 1em" class="maincontent" height="90"> <META HTTP-EQUIV="expires" CONTENT="0"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <link rel="stylesheet" type="text/css" href="style.css"> <?php $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); $login = $_POST["username"]; $password = $_POST["password"]; $field = ""; if (isset($_POST["username"]) and isset($_POST ["password"])) { if (is_numeric('$login')) { $field = "user_id"; } else { $field = "username"; } $query = sprintf ("SELECT * FROM users WHERE $field='$login' AND password='".md5 ($password)."'", mysql_real_escape_string($login), mysql_real_escape_string($password)); $result = mysql_query($query, $connect) or die ("QUERY FAILED: " . mysql_error()); if (mysql_num_rows($result) == 0) { if(session_is_registered("LoginFailed")) { if($_SESSION['LoginFailed'] > 3) { $user_query = mysql_query("SELECT * FROM users WHERE username = '$login'") or die("QUERY FAILED: " . mysql_error()); $user = mysql_query($user_query); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $password_cypt = md5($password); $date = date("YmdHis"); $IP = getenv("REMOTE_ADDR"); $browser = getenv("HTTP_USER_AGENT"); $handle = fopen("ban.txt", "a+"); //echo "sql: ".$query.""; //echo "Login Failed!"; $access_query = "INSERT INTO hacklog (date, username, hostname, ip_address, browser, refer, password) values ('$date', '$login', '$hostname', '$IP', '$browser', '$refer', '$password')" or die("QUERY FAILED: " . mysql_error()); $access = mysql_query($access_query) or die ("QUERY FAILED: " . mysql_error()); $browser = getenv("HTTP_USER_AGENT"); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $date = date("YmdHis"); $rest = substr(getenv('SCRIPT_NAME'), 1, -4); mail("email", "Hack Attack Alert", "Someone Is Attempting To Enter V.I.P\nThe username is: $login\nPassword is: $password\nIP is: $visitorip\nHostname is: $hostname\nBrowser Used is: $browser\nDate: $date\nFile: $rest", "From: email\n"); $browser = getenv("HTTP_USER_AGENT"); $date = date("YmdHis"); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $IP = getenv("REMOTE_ADDR"); $handle = fopen("ban.txt", "a+"); $date = date("m-d-Y H:i:s"); $somecontent = $IP.", ".$date. ", ".$browser.", ".$hostname.""; fwrite($handle, $somecontent . " "); fclose($handle); echo "$IP Is Now Banned. Follow Instructions On Next Screen."; print "<META HTTP-EQUIV=\"Refresh\" target= \"info\" Content=\"1; URL=ban.php\">"; exit(); } else { $_SESSION['LoginFailed'] = $_SESSION ['LoginFailed'] + 1; print "<p><strong>Now " . $_SESSION ['LoginFailed'] . " out of 4 Attempts Used</strong></p>\n"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } } else { $_SESSION['LoginFailed'] = 1; print "<p><strong>You have used " . $_SESSION ['LoginFailed'] . " out of 4 trys</strong></p> \n"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } print "<META HTTP-EQUIV=\"Refresh\" Content=\"1; URL=error.php?msg=pass\">"; exit(); } else { $date = date("YmdHis"); $session = md5($date); $password_cypt = md5($password); $row = mysql_fetch_array($result,MYSQL_ASSOC); $hostname = gethostbyaddr($_SERVER ['REMOTE_ADDR']); $IP = getenv("REMOTE_ADDR"); $browser = getenv("HTTP_USER_AGENT"); $_SESSION["logged"] = "1"; $_SESSION["id"] = $row["user_id"]; $_SESSION["username"] = $row["username"]; $_SESSION["firstname"] = $row["firstname"]; $_SESSION["lastname"] = $row["lastname"]; $_SESSION["email"] = $row["email"]; $_SESSION["created"] = $row["created"]; $_SESSION["last_access"] = $row["last_access"]; $_SESSION["pw"] = $row["pw"]; $_SESSION["permission"] = $row["permission"]; $_SESSION["count"] = $row["count"]; $_SESSION["photo"] = $row["photo"]; $_SESSION["session_id"] = $row["session_id"]; //echo "sql: ".$query."<br>"; //echo "Login success: username: ".$_SESSION ["username"]; //Find Last Access $dd = substr($_SESSION[last_access],6,2); $mm = substr($_SESSION[last_access],4,2); $yyy = substr($_SESSION[last_access],0,4); $HH = substr($_SESSION[last_access],8,2); $MM = substr($_SESSION[last_access],10,2); $SS = substr($_SESSION[last_access],12,2); $access2 = "$mm-$dd-$yyy $HH:$MM:$SS"; $username = $_SESSION["username"]; $access = "$access2"; $login_message = "<p><br> Login Successful.<br><br> [$username] , Last Visited MalenTek On: [$access]<br>Loading Please Wait..<img src=password/images/ajax-loader.gif border=0></p>\n"; if (isset($_POST['blesta']) { print "You are being redirected to your Billing Account"; print "<META HTTP-EQUIV=\"Refresh\" Content= \"10; URL=/cart/u-main.php">"; } else if ($_SESSION[permission] == "1") { $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("file.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=password/admin.php\">"; } else if ($_SESSION[permission] == "0") { $connect = mysql_connect("localhost", "user", "pw") or die("Could not connect to database: " . mysql_error()); mysql_select_db("db", $connect) or die("Could not select database"); mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("file.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=members.php/">"; } else if ($_SESSION[permission] == "2") { mysql_query("UPDATE users SET last_access = $date WHERE username = '$username'")or die("QUERY FAILED: " . mysql_error()); include ("ban.php"); print "$login_message"; print "<META HTTP-EQUIV=\"Refresh\" Content=\"10; URL=index.php\">"; } //} } } ?> </td> </tr> <tr> <td class="hrz_line"><img src="images/spacer.gif" width="1" height="1"></td> </tr> <tr> <td height="20" class="popbot"><a href="mailto:email Errors">Report Errors</a></td> </tr> </table> </body> </html> I'm developing a form which is essentially a simple set of radio buttons. Conceptually, it is like this:
Please select a theme from the list:
o Black
o Blue
o Red
[Submit] [Reset]
I'm actually showing a slideshow of images showing the appearance of each of the themes in a slideshow that only shows one image at a time. I want my users to click on the image that represents the theme they want and, ideally, not have to click on the Submit button at all.
Then I will save the name of the theme they chose in a cookie (if cookies are enabled).
Many years ago, I dabbled in things like CGI and I have a vague recollection, possibly faulty, that it's not difficult to make a form that has only one set of radio buttons treat the selection of one of the radio buttons as a Submit. I don't remember how to do it though.
Can anyone advise me on whether it is indeed possible and, if it is, how I make the selection of the radio button cause the form to be submitted?
Hello guys. I am learning PHP little by little and am writing a VERY basic quiz. For functionality in the future I want to be able to change questions and answers in one "included" php doc. The problem i am having with my current code is that I would like to place a variable in the "value" definition on the radio input. I am unable to do this I guess. Any suggestions to accomplish the same thing? Sorry for my horrible code, this is the first thing I have written from scratch. The form page: Code: [Select] <?php include ("test.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <h2><? print $q1; ?></h2> <form method="post" action="test.php"> <input type="radio" name="q1answered" value="Basketball"/> <?php print $q1ans[0]; ?> <input type="radio" name="q1answered" value="Football"/> <?php print $q1ans[1]; ?> <br /><br /> <input type="submit" value="Submit Your Answer!" name="submit" /> </form> </body> </html> The php Code: [Select] <!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> </head> <body> <?php //Enter all questions below $q1 = "What is your favorite Sport?"; $q2 = "What is your favorite hobby?"; //End Questions //Enter Asnwer choices for each question $q1ans = array("Basketball", "Football"); //End Answers //All question defined variables here to make grading easier $qbank = array ($q1, $q2,); if (isset($_POST["submit"])) { $choice = $_POST["q1answered"]; if ($choice == $q1ans[0]){ print "Your Favorite Sport is $q1ans[0]."; } else { print "Your Favorite Sport is $q1ans[1]."; } } ?> </body> </html> Thanks! I'm totally naive to php coding and i'm trying to modify my website which was written for me by someone else in php. So i'm kind of shooting in the dark - but my modification really isn't that difficult... here goes. I already have a form set up allowing the user to select values from drop down menus. To this I want to add a further selection from a choice of 4 radio buttons. This is the coding I've used (i've stripped it down to basics for simplicity) it's inserted between the 'form' tags <input type=radio name="choice" value="FP"> Front Print<br> <input type=radio name="choice" value="BP"> Back Print<br> <input type=radio name="choice" value="PP"> Pocket Print<br> <input type=radio name="choice" value="CP"> Custom Print<br> Ok - this part displays ok and seems to function as expected. The form 'Action' sends the user to another php page so i need to access these values on a different page. This is where I'm running blind. I just want a simple 'if' statement to set a variable based on the value of the radio buttons. So something that looks like this.... if (choice[1].checked=true) {$printchoice = "Front Print";} if (choice[2].checked=true) {$printchoice = "Back Print";} if (choice[3].checked=true) {$printchoice = "Pocket Print";} if (choice[4].checked=true) {$printchoice = "Custom Print";} This part doesn't work - i've tried various combinations but i'm just taking wild guesses. Any help would be much appreciated - thanks Code: [Select] if ($cartype = 1 ) { echo "Compact <br/>"; } elseif ($cartype == 2 ) { echo "Saloon <br/>"; } else if ($cartype == 3 ) { echo "SUV <br/>"; } This code will only display the first radio button atm. How do I fix this? I have made a form which includes text fields and radio buttons. The user completes the fields and makes their selections. Once the form is submit, they are then directed to a php file which displays their entries and selections. Atm I can't quite work out how to post their radio button selections. Here is the form: <legend>Car type</legend> <input name="cartype" type="radio" value="1" id="carone" /> <label for="carone">Compact</label><br /> <input name="cartype" type="radio" value="2" id="cartwo" /> <label for="cartwo">Saloon</label><br /> <input name="cartype" type="radio" value="3" id="carthree" /> <label for="carthree">SUV</label> and here is my current code for the text fields: <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $emailaddress = $_POST['emailaddress']; $phone = $_POST['phone']; echo "Dear ". $firstname . " " . $lastname . ",<br />"; echo "Thank you for your order. <br />"; echo "Your contact details a - <br />"; echo "phone: " . $phone . "<br />"; echo "email: " . $emailaddress . "<br />"; ?> </body></html> If anyone could give a hand I'd be very grateful! Hi, I have the below code which pulls pet types from the database, and when you pick the particular type by selecting a radio button amd press 'Select Pet Type' you are brought to a page listing all examples of that pet. Is there any way of changing this so the pet types are listed as hyperlinks instead and when you click each particular hyperlink you are brought to a page where that pet type is listed? <?php /* Program: PetCatalog.php * Desc: Displays a list of pet categories from the PetType table. Includes descriptions. * Displays radio buttons for user to check. */ ?> <html> <head><title>Pet Types</title></head> <body> <?php include("misc.inc"); #12 $cxn = mysqli_connect($host,$user,$password,$dbname) #14 or die ("couldn't connect to server"); /* Select all categories from PetType table */ $query = "SELECT * FROM pettype ORDER BY petType"; #18 $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); #20 /* Display text before form */ echo "<div style='margin-left: .1in'>\n <h1 style='text-align: center'>Pet Catalog</h1>\n <h2 style='text-align: center'>The following animal friends are waiting for you.</h2>\n <p style='text-align: center'>Find just what you want and hurry in to the store to pick up your new friend.</p> <h3>Which pet are you interested in?</h3>\n"; /* Create form containing selection list */ echo "<form action='ShowPets.php' method='POST'>\n"; #33 echo "<table cellpadding='5' border='1'>"; $counter=1; #35 while($row = mysqli_fetch_assoc($result)) #36 { extract($row); #38 echo "<tr><td valign='top' width='15%' style='font-weight: bold; font-size: 1.2em'\n"; echo "<input type='radio' name='interest' value='$petType'\n"; #43 if( $counter == 1 ) #44 { echo "checked"; } echo ">$petType</td>"; #48 echo "<td>$typeDescription</td></tr>"; #49 $counter++; #50 } echo "</table>"; echo "<p><input type='submit' value='Select Pet Type'> </form></p>\n"; #54 ?> </div> </body></html> Hi community. The radio buttons on my form suddenly stopped working. For the life of me I can’t figure out why. Everything seems to look fine. I did some moving around on servers so I wonder if something got messed up during the transfer. I’m wondering if a new version of PHP was installed and made something obsolete. I was wondering if someone could take a look. Thank you in advance for your advise.
<form action="brian_1.php" method="post" name="form1" id="form1"> <input name="name" type="text" id="name" size="30" tabindex="1"/> Company if Applicable: <input name="company" type="text" id="company" size="30" tabindex="2"/> Phone: <input name="phone" type="text" id="phone" tabindex="3" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="12"/> Example: XXXXXXXXXX Alternate Phone: <input name="altphone" type="text" id="altphone" tabindex="4" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="13"/> Example: XXXXXXXXXX Street Address:<input name="mail" type="text" id="mail" size="60" tabindex="5"/> City, State, Zip Code: <input name="city" type="text" id="city" size="60" tabindex="5"/> E-mail: <input name="emai" type="text" id="emai" size="60" tabindex="6"/> Would you like to be part of our mailing list? <label><input type="radio" name="list" value="Yes" id="RadioGroup1_0" tabindex="7"/>Yes</label><label><input type="radio" name="list" value="No" id="RadioGroup1_1" tabindex="8"/>No</label> Are you interested in volunteering for upcoming events? <label><input type="radio" name="volunteer" value="Yes" id="RadioGroup2_0" tabindex="9"/>Yes</label><label><input type="radio" name="volunteer" value="No" id="RadioGroup2_1" tabindex="10"/>No</label> Are you interested in becoming a sponsor by receiving opportunities to advertise through us? <label><input type="radio" name="opportunities" value="Yes" id="RadioGroup3_0" tabindex="11"/>Yes</label><label><input type="radio" name="opportunities" value="No" id="RadioGroup3_1" tabindex="12"/>No</label> Would you like to join our efforts by offering your services or products to further our cause? <label><input type="radio" name="cause" value="Yes" id="RadioGroup4_0" tabindex="15"/>Yes</label><label><input type="radio" name="cause" value="No" id="RadioGroup4_1" tabindex="16"/>No</label> If so, in what ways would you like to contribute? <textarea name="contribute" cols="60" rows="4"></textarea> <input type="submit" name="Submit" value="Sumbit" /><input type="reset" name="reset" id="reset" value="Clear" /> </form> <?php /* Email Variables */ $emailSubject = 'Contact Form'; $webMaster = 'brianewagnerfund@gmail.com'; $webMaster = 'matt@webskillsplus.com'; //$webMaster = 'murrterr@rcn.com'; /* Data Variables */ $name = $_POST['name']; $company = $_POST['company']; $phone = $_POST['phone']; $altphone = $_POST['altphone']; $mail = $_POST['mail']; $city = $_POST['city']; $emai = $_POST['emai']; if (isset($_POST["submit"])) { echo $_POST["list"]; } if (isset($_POST["submit"])) { echo $_POST["volunteer"]; } if (isset($_POST["submit"])) { echo $_POST["opportunities"]; } if (isset($_POST["submit"])) { echo $_POST["cause"]; } $contribute = $_POST['contribute']; $body = <<<EOD \r\n \r\n <br> Name(s): $name \r\n <br> Company if Applicable: $company \r\n <br> Phone: $phone \r\n <br> Alternate Phone: $altphone \r\n <br> Street Address: $mail \r\n <br> City, State, Zip Code: $city \r\n <br> Email: $emai \r\n <br> Would you like to be part of our mailing list? $list \r\n <br> Are you interested in volunteering for upcoming events? $volunteer \r\n <br> Are you interested in becoming a sponsor by receiving opportunities to advertise through us? $opportunities \r\n <br> Would you like to join our efforts by offering your services or products to further our cause? $cause \r\n <br> If so, in what ways would you like to contribute? $contribute \r\n <br> EOD; $from = "From: BrianEWagnerFund@gmail.com\r\n"; $from .= "Reply-To: ".$emai."\r\n"; $from .= "Content-type: text/html\r\n"; mail($webMaster, $emailSubject, $body, $from); /* Results rendered as HTML */ echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.brianewagnerfund.org/thankyou.html\">"; ?> I have been searching for something like this to use so I am trying to implement these ideas for my form but unable to get it to work. The concept is similar so I am posting here but if I would make a new post just let me know. it is not posting the info when the radio button is checked. Someone with a keener eye that mine can give a look and tell what I have done incorrectly it would be appreciated. Code: [Select] echo ' <form action="" method="get"><div id="avatar_section"> <div id="avatar_stack"> <p> <img src="herotmb/face0.png" alt="" /><input name="avatar[head]" type="radio" value="face0" checked="checked" /> </p> <p> <img src="herotmb/face0.png" alt="" /><input type="radio" name="avatar[face]" value="face0" /> <img src="herotmb/face1.png" alt="" /><input type="radio" name="avatar[face]" value="face1" /> <img src="herotmb/face2.png" alt="" /><input type="radio" name="avatar[face]" value="face2" /> <img src="herotmb/face3.png" alt="" /><input type="radio" name="avatar[face]" value="face3" /> </p> <span name="color"> <p> <img src="herotmb/color0.png" alt="" /><input type="radio" name="avatar[color]" value="black" id="black" onclick="color(black);" /> <img src="herotmb/color1.png" alt="" /><input type="radio" name="avatar[color]" value="brown" id="brown" /> <img src="herotmb/color2.png" alt="" /><input type="radio" name="avatar[color]" value="darkbrown" id="darkbrown" onclick="color(darkbrown);" /> <img src="herotmb/color3.png" alt="" /><input type="radio" name="avatar[color]" value="yellow" id="red" onclick="color(red);" /> <img src="herotmb/color4.png" alt="" /><input type="radio" name="avatar[color]" value="red" id="yellow" onclick="color(yellow);" /> </p> </span> '; $selected_radio = '$_POST[avatar[color]]'; if ($selected_radio == 'black') { echo ' <p> <img src="herotmb/hair0-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-black" /> <img src="herotmb/hair5-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair5-black" /> <img src="herotmb/hair6-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair6-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'brown') { echo 'Table 2 Here.'; } else if ($selected_radio == 'darkbrown') { echo 'Table 3 Here.'; } else if ($selected_radio == 'red') { echo 'Table 4 Here.'; } else if ($selected_radio == 'yellow') { echo 'Table 5 Here.'; } echo ' <p id="submit" > <input type="submit" value="Save" /> </p> </form>'; I'm not sure how to use foreach to send multiple form information to the database. <form> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="1" checked="checked" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="2" /> <input id="<?php print $row['id'];?>" name="attendance" type="radio" value="3" /> </form> I have a group of 3 buttons for three different options and this is in a php while loop,and there could be anywhere from 1 to 30 of these forms that ineed to send the data to the database at the same time. each one of these groups are next to a user to mark if they were present, tardy, or absent. I need it to get the id of the user for each one of these and send the value to the database as well. Hi guys...I need some help in matching data from results of checkboxs and radio buttons. My Intentions: There are 3 radio buttons and 8 check boxes. Users can select any one but cannot don't select at all. I separate the calss and categories because for classes, users can only select 1 option whereas for categories users can select many. For example, User select class 1 but do not select anything else and click submit...the system will then retrieve that he selected and check the data base if he have the pre requisites to allow him to go through. Coding for my form: Code: [Select] <form id="applicationoptions" method="post" action="s_apply_now.php"> <div id="optionshead">Class :</div> <div id="classoptions"> <input type="radio" name="class" value="1" /> Class 1 Permit <input type="radio" name="class" value="2" /> Class 2 Permit <input type="radio" name="class" value="3" /> Class 3 Permit </div> <div id="optionshead2">Categories :</div> <div id="catoptions"> <input type="checkbox" name="cat" value="1" /> CAT 2PG <input type="checkbox" name="cat" value="2" /> CAT 1OR <input type="checkbox" name="cat" value="3" /> CAT 2TT <br/><br/> <input type="checkbox" name="cat" value="4" /> CAT 3PG <input type="checkbox" name="cat" value="5" /> CAT 2OR <input type="checkbox" name="cat" value="6" /> CAT 3TT <br/><br/> <input type="checkbox" name="cat" value="7" /> CAT 4PG <input type="checkbox" name="cat" value="8" /> CAT 3OR </div> <div class="applynext"> <input class="applynextbutton" type="submit" name="applynextbutton" value="PROCEED" /> </div> </form> Lets say if user do not select any class, but select CAT 3PG, system will check if user have the pre-requisites before proceeding to next step. Any one can help me or give me hints?? most importantly is i do not know how to retreieve the values selected from the form. Is it possible to do it using php or must i hunt for javascript's script?? Thanks in advance guys...greatly appreciate. I have been at this for far too long and really need some help. I am just trying to check if a radio button has been set or not when someone hits submit. My validation looks something like this: function protect($string){ $string = trim(strip_tags(addslashes($string))); return $string; } if(isset($_POST['submit'])){ //protect and then add the posted data to variables $username = protect($_POST['username']); $password = protect($_POST['password']); $passconf = protect($_POST['passconf']); $email = protect($_POST['email']); $fname = protect($_POST['fname']); $lname = protect($_POST['lname']); $address = protect($_POST['address']); $phone = protect($_POST['phone']); $gender = $_POST['gender']; if(!$username || !$password || !$passconf || !$email || !$fname || !$lname || !$address || !$phone || !isset($gender)){ echo "<p>Please enter all required fields</p>"; }else{ and my form for the radio button is like this... <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h1>General</h1> <p> <label for="username">Username: </label> <input type="text" name="username" value="<?=$_POST['username'] ?>" /> </p> <p> <label for="password">Password: </label> <input type="password" name="password" value="<?=$_POST['password'] ?>" /> </p> <p> <label for="passconf">Confirm Password: </label> <input type="password" name="passconf" value="<?=$_POST['passconf'] ?>" /> </p> <p> <label for="email">Email: </label> <input type="text" name="email" value="<?=$_POST['email'] ?>" size="25"/> </p> <p> <label for="fname">First Name: </label> <input type="text" name="fname" value="<?=$_POST['fname'] ?>" size="25"/> </p> <p> <label for="lname">Last Name: </label> <input type="text" name="lname" value="<?=$_POST['lname'] ?>" size="25"/> </p> <p> <label for="address">Home Address: </label> <input type="text" name="address" value="<?=$_POST['address'] ?>" /> </p> <p> <label for="phone">Primary Phone Number: </label> <input type="text" name="phone" value="<?=$_POST['phone'] ?>" size="10" /> </p> <p> <label for="genders">Gender: </label> <input type="radio" name"gender" value="male" /> Male <input type="radio" name"gender" value="female" /> Female </p> everytime i hit submit i get this error: "Notice: Undefined index: gender in C:\wamp\www\LoginRegistration\register.php on line 37 Please enter all required fields" can anyone help me please? Does anyone have any idea how to validate a group of radio buttons with jquery and php..... please need help... ASAP In this form, I am using radio buttons to select various PHP math function results (total, average,both) and it works but was wondering if it is possible to make it multiple choice, that is to say instead of displaying one result at t time when you submit, displaying two or three of the results, depending on how many radio buttons are clicked. Can this be done? Here is the form code <form action="." method="post"> <input type="hidden" name="action" value="process_scores" /> <label>Score 1:</label> <input type="text" name="scores[]" value="<?php echo $scores[0]; ?>"/><br /> <label>Score 2:</label> <input type="text" name="scores[]" value="<?php echo $scores[1]; ?>"/><br /> <label>Score 3:</label> <input type="text" name="scores[]" value="<?php echo $scores[2]; ?>"/><br /> <!-- ADD LOGIC TO DETERMINE WHETHER TO CALCULATE AVERAGE, TOTAL OR BOTH --> <fieldset> <legend> What do you want to calculate?</legend> <p> <input type="radio" name="calculate" value="average" checked="checked" /> Average<br /> <input type="radio" name="calculate" value="total" />Total<br /> <input type="radio" name="calculate" value="both" />Both</p> <p><br /> </p> </fieldset> <br /><br /> <label> </label> <input type="submit" value="Process Scores" /><br /> <label>Scores:</label> <span><?php if (isset($scores_string)) { echo $scores_string; } ?></span><br /> <label>Score Total:</label> <span><?php if (isset($score_total)) { echo $score_total; } ?></span><br /> <label>Average Sco </label> <span><?php if (isset($score_average)) { echo $score_average; } ?></span><br /> </form> and the processing code <?php if (isset($_POST['action'])) { $action = $_POST['action']; } else { $action = 'start_app'; } if (isset($_POST['calculate'])) { $calculate = $_POST['calculate']; } switch ($action) { case 'start_app': $scores = array(); $scores[0] = 70; $scores[1] = 80; $scores[2] = 90; break; case 'process_scores': $scores = $_POST['scores']; // validate the scores $is_valid = true; for ($i = 0; $i < count($scores); $i++) { if (empty($scores[$i]) || !is_numeric($scores[$i])) { $scores_string = 'You must enter three valid numbers for scores.'; $is_valid = false; break; } } if (!$is_valid) { break; } // process the scores $scores_string = ''; $score_total = 0; foreach ($scores as $s) { $scores_string .= $s . '|'; $score_total += $s; } $scores_string = substr($scores_string, 0, strlen($scores_string)-1); // calculate the average $score_average = $score_total / count($scores); // format the total and average switch($calculate) { case 'average': $score_average = number_format($score_average, 2); $score_total = ""; break; case 'total': $score_average = ""; $score_total = number_format($score_total, 2); break; case 'both': $score_total = number_format($score_total, 2); $score_average = number_format($score_average, 2); break; } break; } include 'loop_tester.php'; ?> Hi, I need to analyze a string and get the text between, before, and after the forward slashes.. The string will always look something like this, but will vary: $str = "I will go to the store with <# one/two/three #> people." Then I need to create a form with radio buttons for each choice. In this case (one, two, or three). The text between the <# ... #> could be different every time, and with uknown amount of forward slashes. Here is what I have so far but it doesn't work. Code to find if there are slashes: Code: [Select] preg_match_all( '/([/]+)/',$str,$matches); Code to create html form .. Code: [Select] $i = 0; $html = '<form>'; foreach ($matches[0] as $match){ if ($pos = strpos( $str,$match ) ) === false ) continue; } $html .= '<input type="radio" name="place-' . $i . '" value=". $match . '" /> '; } $html .= '</form>'; Its not working as needed. I'm not sure how to create radio button choices for the words (one, two, three). Thanks Hey all, I'm somewhat new to PHP and working on a form and trying to make radio buttons sticky. I've tried the following but when I refresh/got back to the page then now matter what button I chose it always shows the "4" bedroom or "No". What size of unit do you require? <input type="radio" name="unitsize" value="1 Bedroom" <?php if (isset($_POST['unitsize']) == '1 Bedroom') echo 'checked'; ?>> 1 bedroom <input type="radio" name="unitsize" value="2 Bedroom" <?php if (isset($_POST['unitsize']) == '2 Bedroom') echo 'checked'; ?>> 2 bedroom <input type="radio" name="unitsize" value="3 Bedroom" <?php if (isset($_POST['unitsize']) == '3 Bedroom') echo 'checked'; ?>> 3 bedroom <input type="radio" name="unitsize" value="4 Bedroom" <?php if (isset($_POST['unitsize']) == '4 Bedroom') echo 'checked'; ?>> 4 bedroom Do you require an accessible unit?</td> <input type="radio" name="accessible" value="Yes" <?php if (isset($_POST['accessible']) == 'Yes') echo 'checked'; ?>> Yes <input type="radio" name="accessible" value="No" <?php if (isset($_POST['accessible']) == 'No') echo 'checked'; ?>> No Any help or suggestions are greatly appreciated. |