PHP - Hi , I Have Problem With Form , When I Use Javascript
Hello everyone ,
I have form and I am using action create2.php and everything is working when I want to send to my database information through the form .. This are codes : Code: [Select] <form action="create2.php" method="post"> <p>email</p> <input type="text" name="inputPayer_email" value="" /> <br/> <p>Name</p> <input type="text" name="inputFirst_name" value="" /> <br/> <p>Last name</p> <input type="text" name="inputLast_name" value="" /> <br/> <p>Address 1</p> <input type="text" name="inputAddress_street" value="" /> <br/> <p>Address 2</p> <input type="text" name="inputAddress_city" value="" /> <br/> <p>State</p> <input type="text" name="inputAddress_state" value="" /> <br/> <p>Mobile number</p> <input type="text" name="inputcmd" value=""> <br/> <input type="submit" name="submit" value="submit" /> </form> and create2.php code is Code: [Select] <?php $db_host = "mysqlxxx.host.com"; // Place the username for the MySQL database here $db_username = "nia"; // Place the password for the MySQL database here $db_pass = "pass"; // Place the name for the MySQL database here $db_name = "db"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); ?> <?php $Payer_email = $_POST['inputPayer_email']; $First_name = $_POST['inputFirst_name']; $Last_name = $_POST['inputLast_name']; $Address_street = $_POST['inputAddress_street']; $Address_city = $_POST['inputAddress_city']; $Address_state = $_POST['inputAddress_state']; $cmd = $_POST['inputcmd']; mysql_query("INSERT INTO `transactions` ( `payer_email` , `first_name` , `last_name` , `address_street` , `address_city` , `address_state` , `cmd` , ) VALUES (NULL , '$Payer_email', '$First_name', '$Last_name', '$Address_street', '$Address_city', '$Address_state', '$cmd')") or die(mysql_error()); //!!!!!!!!!!!!!!!!!!!!!!!!! Email User the activation link !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! $to = "$Payer_email"; $from = "admin@mywebsite.com"; $subject = "Your order .."; //Begin HTML Email Message $message = "Hi $First_name, Thank you , bla bla .. "; //end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text\r\n"; mail($to, $subject, $message, $headers); $msgToUser = "Thank you .. "; include_once 'hvala.php'; exit(); // Close else after duplication checks header('Location: hvala.php'); ?> And this is redirecting me to hvala.php and sending e-mail for those who ordered something .. But when I want to add javascript so I can validate my web form , sending information in database is not working . I named form with "m" and action is create2.php , javascript works but my order form is not sending to my database anything .. Only blank fields in database .. I will give code with javascript , so if anyone see where is mistake , please write on thread .. Thank you in advance Code: [Select] <script type="text/javascript" language="javascript"> <!-- function validateMyForm ( ) { var isValid = true; if ( document.m.inputPayer_email.value == "" ) { alert ( "Insert email" ); isValid = false; } else if ( document.m.inputPayer_email.value.length < 1 ) { alert ( "Insert email" ); isValid = false; } else if ( document.m.inputFirst_name.value == "" ) { alert ( "First name" ); isValid = false; } else if ( document.m.inputLast_name.value == "" ) { alert ( "Last name" ); isValid = false; } else if ( document.m.inputAddress_street.value == "" ) { alert ( "Address" ); isValid = false; } else if ( document.m.inputAddress_city.value == "" ) { alert ( "Address" ); isValid = false; } else if ( document.m.inputAddress_state.value == "" ) { alert ( "State" ); isValid = false; } else if ( document.m.inputcmd.value == "" ) { alert ( "Mobile number" ); isValid = false; } return isValid; } //--> </script> <form name="m" action="create2.php""> <p>email</p> <input type="text" name="inputPayer_email" value="" /> <br/> <p>Name</p> <input type="text" name="inputFirst_name" value="" /> <br/> <p>Last name</p> <input type="text" name="inputLast_name" value="" /> <br/> <p>Address 1</p> <input type="text" name="inputAddress_street" value="" /> <br/> <p>Address 2</p> <input type="text" name="inputAddress_city" value="" /> <br/> <p>State</p> <input type="text" name="inputAddress_state" value="" /> <br/> <p>Mobile number</p> <input type="text" name="inputcmd" value=""> <br/> <input name="button" type="submit" value="Submit Information" onclick="javascript:return validateMyForm();"/> </form> Similar TutorialsThis topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=326600.0 Hi, I have this PHP code which displays a form input, but I cannot work out how to add this javascript to the text field. PHP: <?php $data = '<div class="ui-widget infoBoxContainerSearch">' . ' <div class="ui-widget-contentSearch infoBoxContentsSearch" style="text-align: center;">' . ' <div style="text-align: center;">' . tep_draw_form('quick_find', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get') . '' . ' ' . tep_draw_input_field('keywords', '') . ' ' . tep_draw_hidden_field('search_in_description', '1') . tep_hide_session_id() //. tep_image_submit('search_icon.png', MODULE_BOXES_SEARCH_BOX_TITLE) . '</div>' . ' </form>' . ' </div>' . '</div>'; echo $data; ?> JavaScript: value="Search" onfocus="this.value==this.defaultValue?this.value='':null" onblur="this.value==''?this.value=this.defaultValue:null;" Could anyone point me in the right direction? Thanks Let's say I have a form with 5 fields to fill out Is it better practice to use Javascript to ensure that all fields are non-empty, a certain length, contain certain characters, etc. Or should the back end PHP side of things handle this, then return an error code to be printed out, etc Thanks! I'm a major JS noob and this is driving me nuts. I'm trying to use this in a form:
http://reactiveraven...trapValidation/
And using the examples, can't get anything to work. Only my browser's non-js HTML 5 form validation. Anybody have a simple that incorporates both HTML and JS? The examples only show the html.
Hi folks, I have had a developer code a site with the following payment methods: Authorize.net (AIM), Paypal Web Payments Pro, and Cash only. When I submit my payment form with any of the above processors, the page refreshes and deletes all the information recorded. Nothing is submitted through the APIs, recorded in the admin panel of the site or emailed. However, my developer from the Ukraine is able to use the form perfectly. We have tried it on several different computers in the US and none of them work. He and his fellow coders are able to submit information using the forms without a problem and are suggesting that something is wrong on my end. Neither one of us can figure out what the problem is because nothing shows up in the PHP error dumps. Any thoughts? I'm putting my money on Javascript, but I'm not sure. I will post the site if necessary, just request it. This might not be enough info for anyone to help with but I'm taking a chance because I'm at my wits end. I have this relatively simple form on a page called "createquiz.php" which has a select dropdown for every row in the table which triggers the form to submit when an option is chosen. It is then sent to "move.php" to manipulate the data. The gist is that users can go to row 4 (for example) and choose "2" from the drop down menu and it will go to move.php which will then update the id of row 4 to now be 2. Basically just reordering the rows in the table. The weird thing is that when the "option" chosen has a value LESS THAN the value of $info['answerid'] for the chosen row, the form submits fine to move.php (like my example above going from 4 to 2. However, if the "option" chosen has a value GREATER THAN the value of $info['answerid'] for the chosen row (like if the user tried to move row 4 to row 7), the form doesn't submit to move.php and instead the page refreshes with a super weird URL like this... "createquiz.php?move=3&submitthisform=submit&hidden=move&numanswers=3#". I have no code anywhere the tries to build a URL anything like that, so something is going very wrong. It looks like it's taking all of the "names" from my form code below and throwing them into a URL. With this minimal info, just curious if anyone has any idea what type of problem in code could lead to this weird type of URL? FYI, the code that gets the values for $_GET['quizid'] and $info['answerid'] is not shown, but I'm positive that is all working fine so I don't think it's important in regards to this issue, especially because when the problem happens, it's not even getting to the point where it tries to post to that URL. Code: [Select] <form method='post' action='move.php?quizid={$_GET['quizid']}&answerid=" . $info['answerid'] . "'> <select name='move' onChange='this.form.submit();'> <option value='x' >Move to...</option> "; for($i=1; $i<=$lastid;$i++) { echo "<option value='$i'>$i</option>"; } echo "</select> <input type='hidden' name='submitthisform' value='submit' /><input type='hidden' name='hidden' value='move' /><input type='hidden' name='numanswers' value='$lastid' /> </form> Hello everyone I need your assitance a great deal, so I have a form which i submitted to a php file throug ajax and jquery. It is working A ok but I want to be able to submit it with javascript instead, so i don't load any lib. And it is now a problem. The method I use to get the form field names and values in jquery is so simple and dynamic hence if changes are made on the html form i don't have to edit my jquery file to effect the change ie in respect to changing the name of the fields or adding more fields. But I don't know to archieve this using javascript. So i want to post my jquery script, for you all my mighty programmers to assist me get a javascript Clone for me, thank you very much for Helping Jquery file $("form.ajax").on("submit", function(){ var that= $(this); that.find('[name]').each(function(index,value){ var that = $(this), name =that.attr('name'), value =that.val(); data[name]=value; }); return false;}); Now the above code is just my major focus of the script. What it does is that select the form with an ajax class attribute and run a function after the user submits the form. The var that get reference to the above form throug the (this) reference. Next i use find fuction to look through out the open and close of our form.ajax form for any element that has the name attribute and set it into array using the .each(function (index,value){}) this is my main focus how to ilterate through the form looking for name attribute and set my finding into array using javascript. The next that var reference to the find statement and then we steal the name attribute and value from our findings and set an array called data with the stolen name variable as its index n value attribute as its value. Thank you once more my aim again is with the find and array setting statement. This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=330364.0 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! This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=342898.0 I didn;t know if I should put this in javascript or in PHP as it covers both in a way, but as there is nobody in the Javascript forum I put it here. Here is my problem: I have a script that get's info from a mysql database and makes it into a navigation bar (The bar is in Javascript.) And the 'url' bit seems to be the problem. - If I type the url in Manually, "index.php?catt=mainpage-home" Then it works, no problem. But if I type: "' . $rowa['url'] . '" then the menu doesn't drop. The rowa[''] method works fine because it works for the 'name' bit. Just the url seems to not work. I will post the code below. <?php include "../../includes/mysql_connect.php"; include "../../includes/info_files.php"; ?> <link rel="stylesheet" href="http://www.controlhabbo.net/layout/global.css" type="text/css" /> <link rel="stylesheet" type="text/css" href="http://www.controlhabbo.net/layout/menu/anylinkmenu.css" /> <script type="text/javascript"> <?php $result = mysql_query("SELECT * FROM nav_title"); while($row = mysql_fetch_array($result)) { echo 'var ' . $row['id'] . '={divclass:\'anylinkmenu\', inlinestyle:\'width:150px; border: solid black 1px; background:#ebebeb\', linktarget:\'\'} ' . $row['id'] . '.items=[ '; $resulta = mysql_query("SELECT * FROM nav_sub WHERE titlereg='$row[reg]'"); $num = mysql_numrows($resulta); while($rowa = mysql_fetch_array($resulta)) { $url = $rowa['url']; echo ' ["' . $rowa['name'] . '", "index.php?catt=main&page=home"]'; ////// --------- "' . $rowa['url'] . '" ----------------- Here is the error!!! ------------- if($num > 1) echo ','; echo ' '; $num = $num - 1; if($num == 0) { $num = mysql_numrows($resulta); } } echo '] '; } ?> </script> <script type="text/javascript" src="http://www.controlhabbo.net/layout/menu/anylinkmenu.js"></script> <script type="text/javascript"> //anylinkmenu.init("menu_anchors_class") //Pass in the CSS class of anchor links (that contain a sub menu) anylinkmenu.init("menuanchorclass") </script> <div id="navbar"> <div id="navbardropdown"> <?php $resultb = mysql_query("SELECT * FROM nav_title"); while($rowb = mysql_fetch_array($resultb)) { echo '<a href="" class="menuanchorclass" rel="' . $rowb['id'] . '">'; echo '<img src="http://www.controlhabbo.net/layout/images/buttons/' . $rowb['id'] . '.png" style="border-width:0" />'; echo '</a>'; } ?> </div> </div> It's nothing to do with the include files, as it works if I type in the url manually, just not if I use the MY SQL database. Any help would be great! Below here is the php and form i got right now. What i want to achieve is that when i check a checkbox that the TotalCosts will be updated by the matching value, and when i checked multiple boxes that those vallues will be added together. But the most important thing what i want to achieve right now is that when you check a box that the TotalCosts echo on the screen will be updated right away with the correct vallues. I tried some things i found while looking here and on other sites, but nothing seems to be working the way i want. Anyways, here is my php, i hope someone can help me <?php $hire = 60.00; $hire1 = 20.00; $hire2 = 22.50; $TotalCosts = 0.00; ?> <form action="index.php" method="post"> <input type="checkbox" name="hire" value="" />Hire <br /> <input type="checkbox" name="hire1" value="" />Hire1 <br /> <input type="checkbox" name="hire2" value="" />Hire2 <br /> </form> <?php if (isset($_POST['hire'])) { $TotalCosts = $TotalCosts + $hire; } if (isset($_POST['hire1'])) { $TotalCosts = $TotalCosts + $hire1; } if (isset($_POST['hire2'])) { $TotalCosts = $TotalCosts + $hire2; } echo $TotalCosts; ?> I don't know whether this is a PHP or an HTML question. I want to be able to post a preset value to accompany an input text value, and have both values entered in the database record. You can see in the code below that the form asks for names for up to six student groups, such as "Year7", "Year8", "Year9" and so on. What I want my form to do is to post the accompanying preset input name (in this case "group1", "group2", "group3", and so on) to a second column in the same record, so that I can search the records on this preset field. How can I do this? Code: [Select] <table width="750" align="center" cellpadding="4"> <form action="admin_login.php" method="post" enctype="multipart/form-data"> <tr> <td><div align="right"><font size="-1">Student Group 1: </font><font color="#CC0000"> </font></div></td> <td><input name="group1" type="text" value="<?php echo "$group1"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 2: </font><font color="#CC0000"> </font></div></td> <td><input name="group2" type="text" value="<?php echo "$group2"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 3: </font><font color="#CC0000"> </font></div></td> <td><input name="group3" type="text" value="<?php echo "$group3"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 4: </font><font color="#CC0000"> </font></div></td> <td><input name="group4" type="text" value="<?php echo "$group4"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 5: </font><font color="#CC0000"> </font></div></td> <td><input name="group5" type="text" value="<?php echo "$group5"; ?>" /></td> </tr> <tr> <td><div align="right"><font size="-1">Student Group 6: </font><font color="#CC0000"> </font></div></td> <td><input name="group6" type="text" value="<?php echo "$group6"; ?>" /></td> </tr> <tr> <td><div align="right"></div></td> <td><input type="submit" name="Submit" value="Submit Form" /></td> </tr> </form> Hello everyone, I'm creating a user information form which includes an image uploader as well as several text inputs. The problem is with... Code: [Select] <form ENCTYPE = "multipart/form-data"></form> When I have ENCTYPE set to multipart/form-data the image uploader works but not the text inputs. When its not set text inputs work but image uploader doesn't work. Anyone have insight into why this is and a good solution? Thanks When I press submit on the form, I do receive the email, but the text in the fields don't show up. How do I fix this? Thanks. FORM CODE: Code: [Select] <form method="post" id="contacts-form" action="process.php"> <fieldset> <div class="rowElem"> <input type="text" value="Name:" onFocus="if(this.value=='Name:'){this.value=''}" onBlur="if(this.value==''){this.value='Name:'}"> </div> <div class="rowElem"> <input type="email" value="E-mail:" onFocus="if(this.value=='E-mail:'){this.value=''}" onBlur="if(this.value==''){this.value='E-mail:'}"> </div> <textarea onFocus="if(this.value=='Message:'){this.value=''}" onBlur="if(this.value==''){this.value='Message:'}">Message:</textarea> <div class="alignright"><input value="Submit" type="submit" name="submit"></div> </fieldset> </form> PHP CODE: Code: [Select] <?php if(isset($_POST['submit'])) { $to = 'example@example.com' ; //put your email address on which you want to receive the information $subject = 'Contact Form'; //set the subject of email. $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = "<table><tr><td>Name</td><td>".$_POST['Name:']."</td></tr> <tr><td>E-Mail</td><td>".$_POST['E-mail:']."</td></tr> <tr><td>Message</td><td>".$_POST['Message:']."</td> </tr></table>" ; mail($to, $subject, $message, $headers); header('Location: contact.php'); } ?> Hello, Having a problem when putting an xml tag in an input field. The field shows blank in $_POST. Heres some sample code
<!doctype html>
If I put <test in the field it shows up blank in the print of POST. I actually want to pass xml in a hidden field, and it wouldnt work. Tracked it down to this problem. Thanks in Advance Edited May 14, 2020 by derbyshiresoftwareerror How can I get an output where it only shows the name of the drink and quantity where quantity > 0 ? Code: [Select] <?php if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="nl"> <html> <form method="post" action="<?php echo $PHP_SELF;?>"> <?php $drinks = array("cola", "fanta", "bier", "koffie", "thee", "vodka"); $i = 0; echo "<table>"; while ($drinks[$i]) { $listnaam = $drinks[$i] . "_aantal"; $optionlist = "<select name= '$listnaam' ><option>0</option><option>1</option><option>2</option><option>3</option></select>"; echo "<tr><td >" . $drinks[$i] . "</td>"; echo "<td>" .$optionlist . "</td></tr>"; $i++; } echo "</table>"; ?> <input type="submit" value="Toon Output" name="submit"/> </form> <?php } else {echo $drinks;} ?> </html> Im a having a problem and im thinking maybe i cant do it with php and will have to look into java script I have several If statements but will only display two of them below. both inputs run on the same button $_POST['build'] the first if statement updates $naqahdah in the database. Its a number being subtracted. I need the 2nd if statement to grab the new updated naqahdah field in the database before the script reads it. Code: [Select] <?php if ($_POST['build']) { if ($_POST['homes']) { if ($naqahdah < $cost_homes) { }else{ mysql_query("UPDATE systems SET homes= $homes + '".mysql_real_escape_string($_POST['homes'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_homes WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} if(isset($_POST['build'])) { if($_POST['naqahdah_mines']) { if ($naqahdah < $cost_naqahdah_mines) { }else{ mysql_query("UPDATE systems SET naqahdah_mines= $naqahdah_mines + '".mysql_real_escape_string($_POST['naqahdah_mines'])."' WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); mysql_query("UPDATE systems SET naqahdah= $naqahdah - $cost_naqahdah_mines WHERE address = '".mysql_real_escape_string($_GET['planet'])."' AND id = '".($_SESSION['user_id'])."'"); }}} ?> |