PHP - Php, Javascript & Wordpress. Simple Form Question.
Alright, I am struggling to get back into the world of programming. I have background in C++ and Javascript, but this was 7 years ago. I am now trying to develop a plugin for a wordpress website I manage and am having a simple problem. It seems like it is at least.
Here is what I need to accomplish. I am designing a plugin that generates a random string of text on a wordpress page. It uses a shortcode to return a form onto the page where it is placed. The form has 3 elements, a textbox, a dropdown list, and a submit button. I can do all of this so far. Here is where I am a bit lost. When the submit button is pressed, I need it to run a function passing the value selected in the dropdown list. I would like this to be contained on the same page. So I am not sure what I need to put in the action="", and my guess is I would use the post method. The function that generates the text returns a paragraph. So it would function like this... $paraText = genParagraph($txtType); //txtType would be the drop down value Currently, I do this and return the value (after slightly more processing). My guess is I have to use the $_POST[] function to somehow return the data into the text box on the page. I am not exactly sure how to achieve this. Thank you for your help! Similar TutorialsHi, I m doing some work for my self an because of that i been reading a lot arround about PHP, and theres something that i would like to ask a bit of enlightenment. So my question is as the title says about html form's using php to insert data into mysql, i been reading tutorials arround the interwebs and even made afew successful tests, but pretty much all tutorials use 2 files to accomplish this the html file with the form and an insert.php where the actual code is stored so this made me think is this how usually it's done? in over all you will have 1 file for the form, 1 for the insert, 1 for the edit php code and 1 for delete. How do you guys usually do it? PS: one of the tests i did was making 1 single file with all these using an switch. My interest in making this question is solo to learn how other people do it to see if i m in the right way. Thanks in advance. HI,
I have a wordpress site that uses WooCommerce and also WooThemes "Wish list" extension as part of a shop.
I am wanting to hide the "add to cart" button when a price is 0.00 but retain the "Add to Wish List" button.
I have already spoken to WooThemes and there responce is they do not offer coding assistance, i would have to employee someone to look at this for me..
I do have some code that kind of works... in that it does hide the "add to cart" button but it also hides the "add to wish list" button
<?php /* * Swop the 'Free!' price notice and hide the cart with 'Subscription Item' in WooCommerce */ add_filter( 'woocommerce_variable_free_price_html', 'hide_free_price_notice' ); add_filter( 'woocommerce_free_price_html', 'hide_free_price_notice' ); add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' ); function hide_free_price_notice( $price ) { remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 ); remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); return 'Subscription Item'; } ?>I'm no programmer so i have no idea if this is a complex fix or something that maybe you guys on a forum can help out with. If it's out of the scope of general foum help i will have to post a job somewhere to see if i can get some help that way. Many Thanks... Hello, first time poster.. I've looked the web over for a long time and can't figure this one out. - Below is basic code that successfully checks MySQL for a match and displays result. I was debugging and forced the "height" and "width" to be 24 and 36 to make sure that wasn't the problem. That's good.. - I'd like to give the user ability to select width and height from a form.. and have it do an onchange this.form.submit so the form can be changing as fields are altered (thus the onchange interaction) - In a normal coding environment I've done this numerous times with no "Page cannot be displayed" problems. It would simply change one select-option value at a time til they get down the form and click submit... but in WordPress I'm having trouble making even ONE single onchange work! - I've implemented the plugins they offer which allows you to "copy+paste" your php code directly into their wysiwyg editor. That works with basic tests like my first bullet point above. - I've copied and pasted the wordpress url (including the little ?page_id=123) into the form "action" url... that didn't work... tried forcing it into an <option value=""> tag.. didn't work. I'm just not sure. I've obviously put xx's in place of private info.. Why does this form give me Page Cannot Be Displayed in WordPress every time? It won't do anything no matter how simple.. using onchange.. Code.. $con = mysql_connect("xxxx.xxxxxxx.com","xxxxxx","xxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxx", $con); $myprodwidth=24; $myprodheight=36; $result = mysql_query("SELECT * FROM product_sizes WHERE prodwidth='$myprodwidth' and prodheight='$myprodheight'"); while($row = mysql_fetch_array($result)) { echo $row['prodprice']; } mysql_close($con); <form method="post" action=""> <select name="myheight" onchange="this.form.submit();"> <option selected="selected" value="">select height</option> <option value="xxxxxxxxx.com/wordpress/?page_id=199&height=36">36</option> <option value="xxxxxxxxx.com/wordpress/?page_id=199&height=36">48</option> </select> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=351799.0 Hi, I have built a custom php program for a client which takes information submitted in a html form and calculates a persons bmi.
I have tested and it works fine, this is in one page (one file).
My problem is I have tried to insert it in to wordpress using both shortcodes and php tag plugins
(you can't insert php in to posts and pages as standard on wordpress)
and I can't get it to work.
The closest I've got is using a php tag plugin that uses shortcodes to replace <?php & ?> but when I submit, it just reloads the page and form rather than showing the result.
as I've said it works fine outside of wordpress. :-\
<h1>BMI Calculator</h1> <!--bmi form--> <?php if (!isset($_POST['submit'])){ ?> <form action="<?php echo $_SERVER['PHP_SHELF']; ?> "method="post"> <input name="weight" size="3"> Enter your weight in kilograms (KG). </br> </br> <input name="height" size="3"> Enter your height in metres, for example if you're 160cm tall you would type in "1.60". </br> </br> <input type="submit" name="submit" value="Calculate"> </form> <?php } else { $weight = $_POST ['weight']; $height = $_POST ['height']; $bmi_catagory = array("Underweight", "Normal", "Overweight", "Obese"); $bmi = ($weight/$height)/$height; if ($bmi <= 18.5) { echo '<h2>Your bmi is '.round($bmi).'</h2><p>You are '.$bmi_catagory[0] .' Click <a href=\'../bmichecker.php\'>HERE</a> to see how Hypnoslimtize can help you achieve a healthy weight.</p>'; } elseif (($bmi > 18.5) && ($bmi <=24.9)) { echo '<h2>Your bmi is '.round($bmi).'</h2><p>You are '.$bmi_catagory[1] .' Click <a href=\'../bmichecker.php\'>HERE</a> to see how Hypnoslimtize can help you stay healthy and avoid temptations.</p>'; } elseif (($bmi >= 25) && ($bmi <=29.9)) { echo '<h2>Your bmi is '.round($bmi).'</h2><p> You are '.$bmi_catagory[2] .' Click <a href=\'../bmichecker.php\'>HERE<a/> to see how Hypnoslimtize can Help you achieve a healthy body weight.</p>'; } elseif ($bmi >= 30) { echo '<h2>Your bmi is '.round($bmi).'</h2><p> You are '.$bmi_catagory[3] .' Click <a href=\'../bmichecker.php\'>HERE</a> to see how Hypnoslimtize can help you achieve a healthy body weight.</p>'; } else { echo 'Your bmi is '.round($bmi); } } ?> <!--bmi form end--> This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=334084.0 I have a php tutorial that I followed for creating, inserting, selecting and updating a MySQL database with php. Everything works fine so I wanted to put it into Wordpress. I took the code and placed it into the wordpress page and everything worked just fine except the update function. Here is the tutorial I used. http://www.phpsimple.net/mysql_insert_record.html It is also the part I am having trouble with. I am able to create a record and I am also able to select a record but when I choose "update" the form doesn't load the data. It will outside the website but not inside wordpress. I am hoping this is not vague but because of my inexperience I am not sure what else to say. I will be more than happy to provide any other information you need. Hi,
I am trying to convert a php function into perl and need to understand the following line in red :
function pagination($query, $per_page = 10,$page = 1, $url = '?'){ $query = "SELECT COUNT(*) as `num` FROM {$query}"; $row = mysql_fetch_array(mysql_query($query)); $total = $row['num']; $adjacents = "2"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { ......................................... What will be the output of this line above in red. Thank you very much. Regards. Tonya hello all I'm VERY new to php and I just have a simple question how do I bold the output text of this string echo $row['name']."<BR>"; I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. Hi. I have an ID in md5 format but in the database its not. I pass the md5 ID to a page and then I am trying to load the correct record via a look up in the database of that ID. Im wondering is this code possible? <?php $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Thanks what does the # symbol do in php(e.x index.php?cat=1#privacy)? How can i use it? From what i 've seen you use it for changing a whole div without reloading the page like tabs.. Hello everyone! I am a new user and I have a simple question. How do I set a password for a user to log in to my site with PHP? I have no MySQL database just a iOS code/host app. I know this isn’t secure but only me and my friends are on the site. Any help is appreciated. Hi, I'm working on a product page and I got it to list all the products in one column of a table, but when I add a second column it just duplicates the first column. What do I need to change? Code: [Select] <?php require_once("functions.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> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <form action="" method="post" name="catalog"> <?php DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $output = "<table>"; while ($row = mysql_fetch_array($result_set)) { $output .= (" <tr> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> </tr> "); } $output .= "</table>"; echo $output; ?> </form> </body> </html> Lets say I have: $var=5; What would an output look like to get me: 1<br> 2<br> 3<br> 4<br> 5<br> Im at a complete loss! Thanks! if someone can help me out with this, its quite simple but I can't seem to get it to work.. Basically, this is the code I have for now, the issue is if I have 0 product or items, I don't want the sorting option to show up on the page, from the code below, what line can I add tosay that if there is no products in a category, not to show the SORT feature. thanks in advance if anyone can help. {if isset($orderby) AND isset($orderway)} <!-- Sort products --> {if isset($smarty.get.id_category) && $smarty.get.id_category} {assign var='request' value=$link->getPaginationLink('category', $category, false, true)} {elseif isset($smarty.get.id_manufacturer) && $smarty.get.id_manufacturer} {assign var='request' value=$link->getPaginationLink('manufacturer', $manufacturer, false, true)} {elseif isset($smarty.get.id_supplier) && $smarty.get.id_supplier} {assign var='request' value=$link->getPaginationLink('supplier', $supplier, false, true)} {else} {assign var='request' value=$link->getPaginationLink(false, false, false, true)} {/if} <form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}"> <select id="selectPrductSort" onchange="document.location.href = $(this).val();"> <option value="{$link->addSortDetails($request, $orderbydefault, $orderwaydefault)|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'price', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Price: lowest first'}</option> <option value="{$link->addSortDetails($request, 'price', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Price: highest first'}</option> {/if} <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Name: A to Z'}</option> <option value="{$link->addSortDetails($request, 'name', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product Name: Z to A'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'quantity', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'quantity' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='In-stock first'}</option> {/if} </select> <label for="selectPrductSort">{l s='Sort by'}</label> </form> <!-- /Sort products --> {/if} Hi guys, this function below is for card validation, however anycard i enter i get the invalid card number, this is not connected to any gateways, this is just an Luhn card validation demonstration. can you tell me please why i get that? <?php if ($_POST['pay']) { $cardNo = addslashes(strip_tags($_POST['cardNo'])); function luhnCheck($cardNo) { $cardNo = str_replace(" ", "", trim($cardNo)); if(!is_numeric($cardNo) or strlen($cardNo)>19) return false; $skip = $newNum = $total = 0; for($i=0;$i<=(strlen($cardNo)-1);$i++) { if($skip ==0) { $tmpNum = ($cardNo[$i]*2); $total += (strlen($tmpNum)==2 ? (substr($tmpNum, 0, 1)+substr($tmpNum, 1)) : $tmpNum); $skip = 1; }else{ $total += $cardNo[$i]; $skip = 0; } } return (($total % 10) == 0); } /* Example Usage */ if(luhnCheck($_GET['cc'])) { echo("Valid Number."); }else{ echo("Invalid Number."); } } ?> <form name="confirm" method="post" action=""> <input type="text" name="cardNo"> <input type="submit" name="pay" value="Pay Now"> </form> I know it could be a issue with this line if(luhnCheck($_GET['cc'])) { but im wondering where should and how put this cc in my form? regards Hello to everyone I would like to ask for this simple question.. Im trying to put if and else condition on my php code. However this condition is not working.. Code: [Select] if($file == #3#){ echo "No results found"; }else{ echo "results has been found"; } This variable $file is the result after i used an API.. If the API does not see any results they would return #3# as the result. This means they returned a transaction code of 3 which you can see here http://developer.textapp.net/WebService/TransactionCodes.aspx means that there was nothing to return. The condition does not function well even if i make 3 or #3# as part of the condition. Can you help me guys? thanks Hello there fellow programmers, I was just wondering if there was any difference between doing this: Code: [Select] echo "Say Something Here"; and this Code: [Select] echo "Say "; echo "Something "; echo "Here"; Thank you in advance. Notice: I am aware of the fact that they will output the same thing, my question is regarding resources. Hey! I have a drop down field for my "register" form, but this is clearly easy to edit, I just used tamperdata for firefox and yeah...pretty easy, is there any way that you could prevent tampering with the values when submitting this form!? |