PHP - Validations In Forms Are Not Working! (help)
Similar TutorialsHi Guys I'm pretty new to PHP, and I've taken on a small PHP project. My project has (among other things) a page where you can capture/edit users. This involves entering a user name and password on an HTML POST form. Upon submitting the form, the data is set to a php script that writes it to a MySQL database. My problem is this - I need to validate the data before writing it to the database. I have to check that all required fields have values, that the "Password" and "Confirm Password" fields match and that the user did not enter illegal characters (SQL injection). Where should this happen? The script can validate the data, but then I'll still need a way to send the user back to the form and repopulate it automatically with what the user had entered. I can't use GET parameters (due to having to keep the password private). One way of doing it might be to send everything except the password as GET parameters, and force the user to re-enter the password. Am I missing something here? What's the best way of doing validations? Thanks for your input. Cheers, Riaan Hey all, I am programming a form that lets users check which items they would like to appear on the details screen, and also allow them to input their own data. This form is generated dynamically using fields from a database to create each row. I am hitting a roadblock because of two things. 1) Is there a way for the input fields to not be in the submission url (using $GET), if the checkboxes in their rows are not checked? Right now, all of them get submitted. Here is the url now: Code: [Select] creator_custom2.php?product_no[]=9-2-20-198&price_9-2-20-198=9.00&price_9-2-20-204=0.00&price_9-2-20-202=0.00&price_9-2-20-200=0.00&price_9-2-20-206=0.00&price_9-2-20-209=0.00&price_9-2-20-211=0.00&price_9-2-20-195=0.00&price_9-2-20-199=0.00&price_9-2-20-201=0.00&price_9-2-20-205=0.00&price_9-2-20-208=0.00&price_9-2-20-196=0.00&price_9-2-20-210=0.00&price_9-2-20-197=0.00&price_9-2-20-207=0.00&price_9-2-20-203=0.00&price_10-1-20-072=0.00&price_10-1-20-070=0.00&price_10-1-20-071=0.00&price_21404TJXP=0.00&price_21402TJXP=0.00&price_21400TJXP=0.00&price_21396TJXP=0.00&price_21397TJXP=0.00&price_21395TJXP=0.00&price_21398TJXP=0.00&price_21401TJXP=0.00&price_21394TJXP=0.00&price_21399TJXP=0.00&price_21416TJDI=0.00&price_21416TJXP=0.00&price_21419TJDI=0.00&price_21419TJXP=0.00&price_21421TJDI=0.00&price_21421TJXP=0.00&price_21418TJDI=0.00&price_21418TJXP=0.00&price_21415TJDI=0.00&price_21415TJXP=0.00&price_21417TJDI=0.00&price_21417TJXP=0.00&price_21420TJDI=0.00&price_21420TJXP=0.00&price_21398TJDI=0.00&comments=&line=813&discontinued=&seasonal=&newproduct=N&orderby=Description&prices[]=&submit=Create+Design+Sheets Here is what I would like: Code: [Select] creator_custom2.php?product_no[]=9-2-20-198&price_9-2-20-198=9.00&submit=Create+Design+Sheets 2) How would I go about linking the checkbox field with the input field? Perhaps this related to #1, but for instance, if I wanted to check the first box, and input $9.00 in it's price field, how would I display this on the next page? I can show which boxes are checked fine, but pulling the price field for each is eluding me. Here is my code for the form fields: Code: [Select] $selectimages = "SELECT * FROM product WHERE line = '$line' ORDER BY $orderby+0, $orderby"; $run = mysql_query($selectimages) or die (mysql_error()); while ($row = mysql_fetch_assoc($run)) { $productnumber = $row['Number']; $productdescription = $row['Description']; $price = $row['Price']; $newproduct = $row['NewProduct']; echo '<tr> <td align="left" valign="top" bgcolor="#e6e6e6" width="30"><input type="checkbox" value="'.$productnumber.'" name="product_no[]"></td> <td align="left" valign="top" bgcolor="#e6e6e6" width="150">'.$productnumber.'</td> <td align="left" valign="top" bgcolor="#e6e6e6" width="200">'.$linename.'</td> <td align="left" valign="top" bgcolor="#e6e6e6" width="400">'.$productdescription; if($newproduct == 'Y') { echo ' <font color="#FF0000">(new)</font>'; } echo '</td> <td align="left" valign="top" bgcolor="#e6e6e6" width="120">$<input type="text" value="'.number_format($price, 2, '.', '').'" name="price_'.$productnumber.'" size="10" maxlength="10"></td> </tr>'; } Here's the results page, with just random testing code: Code: [Select] $productnumbers = $_GET['product_no']; print_r($productnumbers); $price_list = 'price_'.$productnumbers; echo $_GET['$price_list']; echo $price_list; [attachment deleted by admin] Hello! When I fill my php form in internet explorer or firefox and click on submit, the spry validaitons will be displayed; but using google chrome or safari they are not displayed. I tried the form using safari but on localhost, they are displayed but over the internet the form will skip to the database and will not be validated. What could be the problem please? Code: [Select] //display an external link or form button if ($product_link = $meta['mp_product_link']) { $button = '<a class="mp_link_buynow" href="' . esc_url($product_link) . '">' . __('Buy Now »', 'mp') . '</a>'; } else { if ($all_out) { $button .= '<span class="mp_no_stock">' . __('Out of Stock', 'mp') . '</span>'; } else { $button = '<div class="mp_product_variations" name="variation">'; //create select list if more than one variation if (is_array($meta["mp_price"]) && count($meta["mp_price"]) > 1 && empty($meta["mp_file"])) { // for each as foreach ($meta["mp_price"] as $key => &$value) { $disabled = (in_array($key, $no_inventory)) ? ' disabled="disabled"' : ''; $variation_select = '<form name="' . $key . '" class="mp_buy_form" method="post" action="' . mp_cart_link(false, true) . '">\n'; $variation_select .= '<input type="hidden" name="product_id" value="' . $post_id . '" />'; $variation_select .= '<input type="hidden" name="variation" value="' . $key . '">'; $variation_select .= '<span>' . esc_html($meta["mp_var_name"][$key]) . ' - '; if ($meta["mp_is_sale"] && $meta["mp_sale_price"][$key]) { $variation_select .= $mp->format_currency('', $meta["mp_sale_price"][$key]); } else { $variation_select .= $mp->format_currency('', $value); }$variation_select .= "</span>\n"; if ($context == 'list') { if ($variation_select) { $variation_select .= '<a class="mp_link_buynow" href="' . get_permalink($post_id) . '">' . __('Choose Option »', 'mp') . '</a>'; } else if ($settings['list_button_type'] == 'addcart') { $variation_select .= '<input type="hidden" name="action" value="mp-update-cart" />'; $variation_select .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['list_button_type'] == 'buynow') { $variation_select .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } else { $button .= $variation_select; //add quantity field if not downloadable if ($settings['show_quantity'] && empty($meta["mp_file"])) { $button .= '<span class="mp_quantity"><label>' . __('Quantity:', 'mp') . ' <input class="mp_quantity_field" type="text" size="1" name="quantity" value="1" /></label></span> '; } if ($settings['product_button_type'] == 'addcart') { $button .= '<input type="hidden" name="action" value="mp-update-cart" />'; $button .= '<input class="mp_button_addcart" type="submit" name="addcart" value="' . __('Add To Cart »', 'mp') . '" />'; } else if ($settings['product_button_type'] == 'buynow') { $button .= '<input class="mp_button_buynow" type="submit" name="buynow" value="' . __('Buy Now »', 'mp') . '" />'; } } $variation_select .= "</form>\n"; } //end for each $variation_select .= '</div>'; } else { $button .= '<input type="hidden" name="variation" value="0" />'; } } } Everything inbetween "for each" is being looped, except for the <form>. How can I get it to include <form> and </form> in the loop? I am doing server side validations using php and jquery.Its validating properly.But problem is the erros messages are displaying on the top of the page.I want to display side of field.All of the validations store in array.How to display errors to side of the field. Hi, I built this reg-login file. Note, login.php asks for your login details. The webform (so to speak) uses SELECT sql query to check your login credentials. The reg.php asks for your new acc details. The webform (so to speak) uses INSERT sql query to add your details to db. I got my webform not displayed to you either as registration form or login form. It is a neutral form. It justs asks you for your email. Then checks against db. If it exists, it assumes you existing member and login() function takes over and logs you in. Else, registration() functions takes over and registers you. Note:
On the login(), at the end when user is logged into his member account, his personal details get displayed on screen. if($row = mysqli_fetch_array($result_3,MYSQLI_ASSOC))
1. I want you to see if there any errors in my code that will result in malfunction or hacker sql injecting or hacking. 2. I need you to show me how to VALIDATE user input. VALIDATE email using 1). html5 & 2). php 7 email validation function plus 3.) with REGEX so nothing but email is inputted. Show me these 3 ways to check for email. I need you to show me how to VALIDATE user password. VALIDATE password using 1). html5 & 2). php 7 & 3.) with REGEX so nothing but password (A-Z, 0-9 ONLY) is inputted. And no other chars. Show me these 3 ways to check for password. From there, I should pick on fast from you and manage to VALIDATE username input.
I don't know how to do these above 2 so kindly teach me by showing snippet with comments so i understand your snippet. NOTE:
I did not complete the password prompt because I have forgotten how to do it with SHA256. Can someone show me a typical example how to query for password with SHA256 or whatever the latest strong algorithm is ? Show me code with comments so I understand what you doing with your code.
Thank You!
<?php session_start(); if($_SERVER['REQUEST_METHOD'] == 'POST') { if(!isset($_POST['email_account']) || !isset($_POST['email_service'])) { $email_error = "<font color='red'>Input Email Address!</color>"; } else { //Connect to Database. (DB_SERVER, BD_USERNAME, DB_PASSWORD, DB_NAME). $conn = mysqli_connect("localhost","root","","powerpage"); $conn->set_charset('utf8mb4'); //Always set Charset. if($conn === false) { die("ERROR: Connection Error!. " . mysqli_connect_error()); } else { //Set Parameters. $email = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]); $_SESSION['email'] = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]);//If this fails on test then replace it with above line echo "line 25 triggered: $email<br>"; $sql_query = "SELECT COUNT(personal_email) FROM users WHERE personal_email = ?"; $stmt = mysqli_prepare($conn,$sql_query); if($stmt == False) { //Close Connection. mysqli_close($conn); echo "Line 33<br>";//DELETE THIS die("<pre>Mysqli Prepare Failed!\n".mysqli_stmt_error($stmt)."\n$sql_query</pre>"); } else { mysqli_stmt_bind_param($stmt,'s',$email); if(!mysqli_stmt_execute($stmt)) { //Close Connection. mysqli_close($conn); die("Could not mysqli_stmt_execute! Please try again later!"); } $result = mysqli_stmt_get_result($stmt); if(mysqli_fetch_array($result, MYSQLI_NUM)[0])//WHY THIS NOT WORK UNLESS NUM ARRAY GIVEN ? { echo "Line 57 triggered: Function login() will trigger!<br>"; //DELETE THIS $_SESSION['session_type'] = 'login'; login(); } else { echo "Line 61 triggered: Function register() will trigger!<br>"; //DELETE THIS $_SESSION['session_type'] = 'register'; register(); } } } } } function register() { //if(!isset($_SESSION['session_type'] or $_SESSION['session_type'] != 'registration')//Nog Dog's copied & pasted line if(!isset($_SESSION['session_type']) || $_SESSION['session_type'] != 'register') { //Close Statement. mysqli_stmt_close($stmt); //Close Connection. mysqli_close($conn); die("Line 86: Could not check email! Please try again later!"); } //$email = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]); $email = $_SESSION['email'];//If this fails on test then replace it with above line //Connect to Database. (DB_SERVER, BD_USERNAME, DB_PASSWORD, DB_NAME). $conn = mysqli_connect("localhost","root","","powerpage"); //Prepare an INSERT Statement. $sql_query_2 = "INSERT INTO users (personal_email) VALUES (?)"; if(!$stmt_2 = mysqli_prepare($conn,$sql_query_2)) { //Close Connection. mysqli_close($conn); die("Could not register! Please try again later!"); } else { //Bind Variables to the Prepared Statement as parameters. mysqli_stmt_bind_param($stmt_2,'s',$email); //Attempt to execute the Prepared Statement. if(!mysqli_stmt_execute($stmt_2)) { //Close Statement. mysqli_stmt_close($stmt_2); //Close Connection. mysqli_close($conn); die("Could not register! Please try again later!"); } mail(); } } function login() { if(!isset($_SESSION['session_type']) || $_SESSION['session_type'] != 'login') { //Close Statement. mysqli_stmt_close($stmt); //Close Connection. mysqli_close($conn); die("Could not check email! Please try again later!"); } //$email = trim($_POST["email_account"]) . '@' . trim($_POST["email_service"]); $email = $_SESSION['email'];//If this fails on test then replace it with above line //Connect to Database. (DB_SERVER, BD_USERNAME, DB_PASSWORD, DB_NAME). $conn = mysqli_connect("localhost","root","","powerpage"); //Prepare a Select Statement. $sql_query_3 = "SELECT id,username,first_name,middle_name,surname,gender,age_range FROM users WHERE personal_email = ?"; if(!$stmt_3 = mysqli_prepare($conn,$sql_query_3)) { //Close Statement. mysqli_stmt_close($stmt_3); //Close Connection. mysqli_close($conn); die("Could not check email! Please try again later!"); } else { //Bind Variables to the Prepared Statement as parameters. mysqli_stmt_bind_param($stmt_3,'s',$email); //Attempt to execute the Prepared Statement. if(!mysqli_stmt_execute($stmt_3)) { //Close Statement. mysqli_stmt_close($stmt_3); //Close Connection. mysqli_close($conn); die("Could not check email! Please try again later!"); } //mysqli_stmt_bind_result($stmt,$email); $result_3 = mysqli_stmt_get_result($stmt_3); //if(mysqli_fetch_array($result_3, MYSQLI_NUM)) //Fetch result row as an associative array. Since the result set contains only one row, we don't need to use the 'While loop'. //mysqli_stmt_fetch($stmt);//use this if you use 'mysqli_stmt_bind_result($stmt,$email). if($row = mysqli_fetch_array($result_3,MYSQLI_ASSOC)) //Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of 'mysqli_stmt_bind_result($stmt,$email)'. { //Retrieve Values. $id = $row["id"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $username = $row["username"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $first_name = $row["first_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $middle_name = $row["middle_name"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $surname = $row["surname"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $gender = $row["gender"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; $age_range = $row["age_range"];//Use this if you use '$result = mysqli_stmt_get_result($stmt)' instead of //'mysqli_stmt_bind_result($stmt,$email_count)'; echo "Id: $id<br>"; echo "Username: $username<br>"; echo "First Name: $first_name<br>"; echo "Middle Name: $middle_name<br>"; echo "Surname: $surname<br>"; echo "Gender: $gender<br>"; echo "Age Range: $age_range<br>"; //Close Statement. mysqli_stmt_close($stmt_3); //Close Connection. mysqli_close($conn); } } } //DO NOT NEED TO REDO THE HTML CODE BELOW AS WAS NOT COPY & PASTE FROM ELESEWHERE .... ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta name="viewport" content="width=device=width, initial-scale=1"> </head> <body> <form action="" method="post"> <label for="email_account">Email:</label> <input type="text" name="email_account" id="email_first_part" placeholder="Email Address before '@'"> <label for="email_service"><b>@</b></label> <input type="text" name="email_service" id="email_last_part" placeholder="Email Address after '@'"> <?php if(!empty($email_error)){echo $email_error;}?> <br> <button type="submit" class="login_register" name="login_register">Register/Login</button> </body> <html> <?php ?>
This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=323416.0 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?? http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> i dont understand what is wrong plz help me.
here is code
$name = "img/".rand(1,9999999).".png"; $myFile = $name; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $html; fwrite($fh, $stringData); fclose($fh); $file=$name; $fst=file_get_contents($file); $im=imagecreatefromstring($fst); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_NEGATE); //Convert to Grey Scale for($i=0;$i<123;$i++){ for($j=0;$j<50;$j++){ $px=imagecolorat($im,$i,$j); if($px<0x303030){ imagesetpixel($im,$i,$j,0); }else{ imagesetpixel($im,$i,$j,0xffffff); } } } $database = unserialize(@file_get_contents("db.txt")); if($database === false) $database = array(); // modify the database if needed if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['submit'] == 'Add') $database[$_POST['ident']] = substr($_POST['letter'], 0, 1); if($_POST['submit'] == 'Del') unset($database[$_POST['ident']]); if($fh = @fopen('db111.txt', 'w+')){ fwrite($fh, serialize($database)); fclose($fh); } }else{ $newimage = true; } $width = 130; $height = 40; $captcha_gridstart =1; $captcha_gridspace =2; $letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace); $count = count($letters); $cellw = ($count > 0) ? intval(100 / $count) : 0; //dispeckle the image and GET co-ordinates of the characters of captcha image and return them. function findletters($image, $width, $height, $gridstart, $gridspace){ $offsets = array(); $o = 0; $atstartx = true; for($x = 0; $x < $width; $x++){ $blankx = true; for($y = 0; $y < $height; $y++){ if(imagecolorat($image, $x, $y) == 0){ $blankx = false; break; } } if(!$blankx && $atstartx){ $offsets[$o]['startx'] = $x; $atstartx = !$atstartx; }else if($blankx && !$atstartx){ $offsets[$o]['endx'] = $x; $atstartx = !$atstartx; $o++; } } $count = $o; for($o = 0; $o < $count; $o++){ for($y = 0; $y < $height; $y++){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['starty'] = $y; break; } } for($y = $height-1; $y > $offsets[$o]['starty']; $y--){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['endy'] = $y; break; } } } for($o = 0; $o < $count; $o++){ $offsets[$o]['ident'] = ""; for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){ for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){ $offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1"); #echo $offsets[$o]['ident'].'<br>'; } } } return $offsets; } $a=""; foreach($letters as $letter){ $asciiletter = $database[$letter['ident']]; if(!empty($asciiletter)) { $a.=$asciiletter; } } I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated. The custom field in wp:
'label' => 'Hide newsletter ads', 'name' => 'hide_ads', 'type' => 'checkbox', 'instructions' => 'Checking the checkbox will remove ads', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Hide newsletter ads' => 'Hide newsletter ads', ), 'allow_custom' => 0, 'default_value' => array( ), 'layout' => 'block', 'toggle' => 0, 'return_format' => 'value', 'save_custom' => 0, ),
This is the php code for it: <!doctype html> <html lang="en-GB"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="x-apple-disable-message-reformatting"> <title><?php the_title(); ?></title> <style> <?php require ABSPATH . 'path/newsletter.css'; ?> </style> <!--[if mso]> <style type="text/css"> .outlook-fallback-font { font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } </style> <![endif]--> </head> <?php $hide_newsletter_ads = get_field('hide_ads'); echo $hide_newsletter_ads; ?> <body itemscope itemtype="http://schema.org/EmailMessage"> <div class="wrap"> <?php if (!$hide_newsletter_ads) { include ABSPATH . 'path/ad-banner.php'; } ?> <div class="header"> <a href="<?php bloginfo( 'url' ); ?>"> <img src="<?php echo get_home_url().'logo.png' ?>" alt="News" /> </a> </div> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( get_field( 'newsletter_summary' ) ) { ?> <div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div> <?php } ?> <?php if ( have_rows( 'newsletter_content' ) ) : ?> <?php // Loop through the ACF blocks $count = 0; while ( have_rows( 'newsletter_content' ) ) : the_row(); if ( get_row_layout() === 'story' ) : ?> <?php if ( 0 === $count ) { ?> <span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span> <?php } ?> <?php if ( get_sub_field( 'story_heading' ) ) : ?> <h1><?php the_sub_field( 'story_heading' ); ?></h1> <?php endif; ?> <div class="content"> <?php the_sub_field( 'story_content' ); ?> </div> <?php endif; if ( 'post_list' === get_row_layout() ) : ?> <?php $posts = get_sub_field( 'post_list' ); if ( $posts ) : ?> </div> <div class="story-list"> <h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2> <div class="wrap-table"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php // Output story cards foreach ( $posts as $i => $post ) { if ( 0 === $i % 2 ) { echo '<tr>'; } $class = ( 0 === $i % 2 ) ? 'odd' : 'even'; $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) ); $image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) ); echo sprintf( '<td class="story-cell %4$s" valign="top"> <a href="%1$s" class="story-card outlook-fallback-font"> <img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" /> <span>%2$s</span> </a> </td>', esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink esc_html( get_the_title( $post->ID ) ), // title // esc_attr( $image_src[0] ), // image - src esc_attr( $image_src[0] ), // image - src esc_attr( $class ) // class ); if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) { echo '</tr>'; } } ?> </table> </div> </div> <div class="wrap"> <?php endif; endif; if (!$hide_newsletter_ads) { (0 === $count) { include ABSPATH . 'path/mpu-1.php'; } if (1 === $count) { include ABSPATH . 'path/mpu-2.php'; } } $count++; endwhile; endif; ?> <div class="footer"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> © <?php echo esc_html( date( 'Y' ) ); ?> </td> <td class="footer-link"> <a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> · <a href="%unsubscribe_url%">Unsubscribe</a> </td> </tr> </table> </div> </div> <?php endwhile; endif; ?>
I need someone that is really good with php forms, looking for major help. Hi there, I'm new to php/MySQL. Just wondering how to create a multipage form with a back, save and submit button. Also, how do you stored the form data into the datebase and how do you display a list of submitted forms by the user to the user. I am attempting to create a login page, but my script is giving errors in relation to the forms. Involved PHP: Code: [Select] $username = mysql_real_escape_string($_POST['username']); if ($_POST['submit']=='Login') { $md5pass = md5($_POST['password']); $sql = "SELECT id,username FROM members WHERE username = '$username' AND password = '$md5pass'"; //etc etc... Involved HTML: Code: [Select] <form id="f6" action="" method="post" onsubmit="return weCheckForm(this)"> <fieldset id="e6" class="cc32"> <label id="e5" class="cc33" for="e4"> Username </label> <input id="e4" class="cc34" type="text" name="username" title="username" size="23"><br> <label id="e3" class="cc33" for="e2"> Password </label> <input id="e2" class="cc34" type="password" name="password" title="password" size="23"><br> <input id="e1" class="cc35" type="submit" title="submit" value="Login"> </fieldset> </form> Errors received: Notice: Undefined index: username in C:\(etc etc...) on line 4 Notice: Undefined index: submit in C:\(etc etc...) on line 6 Now I know that the problem is username and submit are undefined. However, I do not know how to define them in relation to the forms. ok i have a questions i making a form so when users sign up to my website they we have an account page and in the account page the will have some more fields they need to filll in which i would use INSERT to put the things inside my db but what if they want to update there account should i use UPDATE Hello, I just assembly a form and for styling it I am using CSS in an external file. Problem is that IE8 and I don't know about 7 (in IE9 is ok) it doesn't show the styling inside the form... My structure is something like this: (in any other situation my css styling is displayed normally) Code: [Select] <form> <span class="myclass"> </span> </form>Is there any fix for it? Thank you We have this form that customers can make their own contact forms, and then it gets inserted to the database. We can show the forms with no problems, the problem lies when someone hits submit, how do I echo out the values of the form when I'm not sure what the input name or id is going to be? This sample form generated this code Code: [Select] <div class="element"> <label id="label-element-3" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Email</span> <span class="required">*</span></label> <div class="errormessage" id="errormessage-element-3"></div> <div class="option-container"> <input class="af-inputtext af-email af-formvalue " type="text" name="element-3" id="element-3" value="" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:260px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;"></div> </div> <div class="element"> <label id="label-element-4" class="label" style="color:#4DBCE9;font-family:Trebuchet MS;font-size:1.2em;font-weight:normal;"> <span class="labelelementvalue">Textarea</span></label> <div class="errormessage" id="errormessage-element-4"></div> <div class="option-container"> <textarea class="af-textarea af-formvalue " name="element-4" id="element-4" style="color:#000000;font-family:Verdana;font-size:0.8em;font-weight:normal;width:300px;border-style:solid; border-color:#dcdcdc;-moz-border-radius:5px;-khtml-border-radius:5px;-webkit-border-radius:5px;border-radius:5px;border-width:1px;padding:5px;" rows="6"></textarea></div> </div> <div class="element"> </div> If you notice, each input type is named "element-" with a number afterwards. So each input could be like "element-4", "element-21", and so forth. How would I post those values of the input fields when they are automatically named? Thanks in advance i need a form that is hidden until the user clicks a button on a calendar only Then the form will be visible and have a field for the day that way pressed on submit the form would go back to being invisible.
not sure how to implement this can anyone help
I am starting to build out a class to handle forms. I want to be able to add and edit data in some cases and just add data in other cases. Also want to do some ajax stuff to prevent from having to reload the pages in certain cases. I would like to view how some other form classes work so I can model mine to what I like about others but suit my needs. I was wondering if anyone has worked with any preexisting form classes that they could recommend. I know libraries like zend and so on have these built in and wasnt sure if anyone liked any one specifically and why. I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. |