PHP - Form Multiple Input Name
I have a form:
<input id="house" name="element_1" class="element radio" type="radio" value="Daniel" />
<input id="car" name="element_2" class="element radio" type="radio" value="Joe" />
How can I give to "element_1" multiple value instead of only one?
Welcome <?php echo $_GET["element_1"]; ?><br> ==== Welcome Daniel
element_1 = element_12 = element_13
WHERE
element_1 = Daniel
element_12 = car
element_13 = key
Welcome <?php echo $_GET["element_12"]; ?><br> ==== Welcome car
I need to create a structure for a 10 different values. I heard that will be easy to use array or object, I don t really now how to structure it.
Similar TutorialsI have a textarea feild in my form where the user can type in several keywords such as Textarea Box Below Cars Trains Buses I have a database with the meanings of the words entered and want to be able to get the three definitions from the database on for submission. In a normal input box where i only type one word i can grab no problem like so $word = $_POST['word']; $sql = "SELECT meaning FROM table WHERE word='$word'"; Though i am trying to get multiple values from the same textarea box So if a user types in 3 words the query would query the database on thoses three words, the problem is i dont know how to get the diffrent words from the form for example $first = $_POST['word']; which would be the first word $sec = $_POST['word']; which would be the second word etc. Any help here would be great thanks. Hey all, I am building a simple cms. I have a posts table and I have an images table. A post has many images and images has a foreign key to the posts table. So when a user edits, updates, creates, and deletes a post, they affect the images related to the post. Sometimes a post can have more than one image, like three images. Hence I rendered this in the view (note that I am using a datamapper that converts tables to objects and fields to key/value pairs): Code: [Select] foreach($records as $post){ echo form_open_multipart("homes/update/$post->id"); //File uploads require a multipart form. Default form handling uses the application/x-www-form-urlencoded content type. Multipart forms use the multipart/form-data encoding. //this is critical to pass the id as part of the action attribute of the form, so we can use our params hash to target the id to update the specific record echo label('Update Title'); echo form_input('title',$post->title); echo label('Update Body'); echo form_textarea('body',$post->body); $images = $post->images->include_join_fields()->get(); if(!is_null($images->image_file_name)){ echo label('Update Images'); foreach($images as $image){ echo form_upload('image_file_name',$image->image_file_name); } } } echo form_submit('submit','Update'); The above line of code will render a few input file types. The problem occurs during posting to my update method. It is looking for one parameter from the input file field and so if I upload three different images, it will only look for one and write only one to database: Code: [Select] $field_name = 'image_file_name'; if ( ! $this->upload->do_upload($field_name)){ $error = array('error' => $this->upload->display_errors()); echo $error['error']; // redirect('homes/edit'); } else { $data = array('upload_data' => $this->upload->data()); $image_file_name = $data['upload_data']['file_name']; Is it possible to do wht I am trying to do? Should I only have on input file type per form submission or is that I need to fix the code to accomodate for multiple submissions by creating an array of sorts? Thanks for response. Long time lurker, first time poster here. I am having a problem with a multiple file uploader form I am trying to build. I am using the CodeIgniter framework, but I believe my problem is with the form itself. Here is the form: Code: [Select] <form action="http://localhost/show/submit" id="sendfiles" method="post" name="sendfiles" enctype="multipart/form-data"> <input type="hidden" name="doup" value="1" /> <input type="file" name="userfile1" value="" id="userfile1" size="20" /> <br /> <input type="file" name="userfile2" value="" id="userfile2" size="20" /> <br /> <input type="file" name="userfile3" value="" id="userfile3" size="20" /> <br /> <input type="submit" name="submit_btn" value="Upload" /> </form> The form is being passed to this function: if(empty($_POST['doup'])){ foreach($_REQUEST as $k => $v) print ">>> $k : $v <br />"; $data['form_open'] = form_open_multipart(uri_string(), array( 'id' => 'sendfiles', 'method' => 'post', 'name' => 'sendfiles' )); $data['form_flag'] = form_hidden('doup', '1'); $data['file1'] = form_input(array( 'id' => 'userfile1', 'name' => 'userfile1', 'size' => '20', 'type' => 'file', )); $data['file2'] = form_input(array( 'id' => 'userfile2', 'name' => 'userfile2', 'size' => '20', 'type' => 'file', )); $data['file3'] = form_input(array( 'id' => 'userfile3', 'name' => 'userfile3', 'size' => '20', 'type' => 'file', )); $data['form_submit'] = form_submit('submit_btn', 'Upload'); $data['form_close'] = form_close(); $this->load->view('show/submit', $data); } else { $config['allowed_types'] = 'mp3'; $config['max_size'] = '10240'; $config['upload_path'] = $this->config->item('file_upload_path'); $uploaded_files = array(); for($nona=1; $nona<4; $nona++){ if (strlen($_FILES['userfile'.$nona]['tmp_name']) <=0){ echo "tempname$nona failed"; continue; } //print "------ USERFILE $nona ------ <br />"; //print sizeof($_FILES['userfile'.$nona])."<br />"; //foreach ($_FILES['userfile'.$nona] as $k => $v){ // print "$k : $v <br />"; //} $this->upload->initialize($config); $upload = $this->upload->do_upload('userfile'.$nona); if (!$upload){ $form_errors = array('form_errors' => $this->upload->display_errors()); $this->load->view('show/submit', $form_errors); break; } else { $data = array('upload_data' => $this->upload->data()); $data = $data['upload_data']; $fp = $data['full_path']; $filename = strtolower(random_string('numeric', 16) . $data['file_ext']); $rel_path = 'show/submissons/uploaded/'; $path = $this->config->item('media_root_path') . $rel_path; exec('mkdir -p ' . $path , $a1, $r1); exec('mv ' . $fp . ' ' . $path . $filename, $a2, $r2); array_push($uploaded_files, $path . $filename); } } $this->session->set_flashdata('img_data',implode("||", $uploaded_files)); // redirect("show/submit_info"); } The problem is this: When I choose only one file to upload, it works. I can choose any of the 3 inputs and it works great. But as soon as I try to choose 2 or more files, the form fails to post. When I press submit, the page simply reloads and none of the form variables get posted. I have checked settings in php.ini and tried building and rebuilding this form. I'm hoping someone here can provide some insight into what I'm doing wrong? First, Happy X-Mas to all! I want to do a form for entering dog-show results. On first site of form the user is able to enter how many dogs for each class (there are youth and open class for example) he want to insert. So on second site there will be formfields for every dog in every class, created with php. User should be able to take dogname from jquery autocomplete - this works for multiple fields. But i need the according id to the dogname - and actual only one id is given - the first one is changing by choosing from autocomplete in next fields... Data came from a json array like 0: {dogidindatabase: "9892", value: "Excalibur Khali des Gardiens de la Cour ",…} dogidindatabase: "9892" label: "<img src='../main/img/female.png' height='20'>Excalibur Khali des Gardiens de la Cour " value: "Excalibur Khali des Gardiens de la Cour " 1: {dogidindatabase: "15942", value: "Excalibur from Bandit's World Kalli",…} dogidindatabase: "15942" label: "<img src='../main/img/male.png' height='20'>Excalibur from Bandit's World Kalli" value: "Excalibur from Bandit's World Kalli"all i need is inside ... the script in form is <script type='text/javascript'> //<![CDATA[ $(function() { $(".dog").autocomplete({ source: "xxx.php", minLength: 3, select: function(event, ui) { $('#dogidindatabase').val(ui.item.dogidindatabase); } }); $["ui"]["autocomplete"].prototype["_renderItem"] = function( ul, item) { return $( "<li></li>" ) .data( "item.autocomplete", item ) .append( $( "<a></a>" ).html( item.label ) ) .appendTo( ul ); }; }); //]]> </script>and the form looked like <input type='text' name='dog' class='dog' value='".strip_tags(${'dogname' .($countbabymale+1)})."' size='35' data-required='true' /><br> <input class='readonly' readonly='readonly' type='text' id='dogidindatabase' name='dogidindatabase' size='5' />I changed in script and form id='dogidindatabase' to class, but it doesn´t work. Testsite is under http://www.wolfdog-d...how.php?lang=de (only german at first) - Insert a number (higher than 1) under baby 3-6 (first box, the others are not working for testing); submit to get to page 2; you see all post-variables (for testing). Try to insert a dogname in first input-field (choose "exc") and insert first one - the id is under dogname. In second dogname inputfield you can choose second dog - the id for the first one changes to id of seond one .... How can i get both for every dog? I have the form: This seems to be a bit of a challenge but I am creating a multiple page form and on one of the pages I have a select field. I would like the user to have the ability to select multiple options but I am using some functions to move the data in hidden fields from page to page. I don't think my functions are jiving with my my foreach loop cause I keep getting an invalid argument error. Thanks in advance for any help. Here is my function: function setSelected($fieldName, $fieldValue) { if(isset($_POST[$fieldName]) && $_POST[$fieldName] == $fieldValue) { echo 'selected="selected"'; } } And here is my loop: $selections = ""; if(isset($_POST["selections"])) { foreach ($_POST["selections"] as $selection) { $selections .= $selection . ", "; } } Hi all . In my scripts , there is a textbox that allow user to enter multiple phone number separate with "," , if all valid it will echo "ok!" else will echo "error" . How if I want to know which value is in wrong format? such as I entered "0112255666,445221122200" , then it will echo " 445221122200 is not a valid phone number" . And how to echo the total phone number inserted to the textarea ? Thanks for every reply . Code: [Select] <?php if (isset($_POST["Submit"])) { $arrLines = split(",",$_POST['cellphonenumber']); foreach($arrLines as $cells){ if(!preg_match('/^[0]{1}[1]{1}[0-9]{1}[0-9]{7}?$/', $cells)){ echo "error"; } else{ echo "ok!"; } } } ?> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" name="myform" method="post"> <textarea name="cellphonenumber" rows="20" cols="100"></textarea> <input type="submit" name="Submit" /> </form> I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug I need to know how to echo multiple things on the same page. If you do understand the last line then don't read this next part. So say if had just a textbox and a submit button. I already know how to make it where they type something and they hit submit and echo's to the page. But after it echos I want to know how to make it where if they entered in another body of text it would enter on the same page right under the last echo, or the last thing they typed. So if you could help me with this or just post a code for me that would be nice. I have read around and can't seem to find the right coding for what I need on this forum and some other other forums. I have a contact form (as listed below) and I need 2 locations (Print Name and Title) fields to auto-populate on a separate form (can be a doc, pdf, etc. any form of document which is easiest) and this form can be totally back end and the individual using the form never is going to see the form. It's going on a contract form, that we would like to auto-populate. Also is there a simple attachment code so individuals can attach documents to the code? <p style: align="center"><form action="mailtest.php" method="POST"> <?php $ipi = getenv("REMOTE_ADDR"); $httprefi = getenv ("HTTP_REFERER"); $httpagenti = getenv ("HTTP_USER_AGENT"); ?> <input type="hidden" name="ip" value="<?php echo $ipi ?>" /> <input type="hidden" name="httpref" value="<?php echo $httprefi ?>" /> <input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" /> <div align="center"> <p class="style1">Name</p> <input type="text" name="name"> <p class="style1">Address</p> <input type="text" name="address"> <p class="style1">Email</p> <input type="text" name="email"> <p class="style1">Phone</p> <input type="text" name="phone"> <p class="style1">Debtor</p> <input type="text" name="debtor"> <p class="style1">Debtor Address</p> <input type="text" name="debtora"> <br /> <br /> <a href="authoforms.php" target="_blank" style="color:#ffcb00" vlink="#ffcb00">Click here to view Assignment Agreement and Contract Agreement</a> <p class="style1"><input type='checkbox' name='chk' value='I Have read and Agree to the terms.'> I have read and agree to the Assignment and Contract Agreement <br></p> <p class="style1">Print Name</p> <input type="text" name="pname"> <p class="style1">Title</p> <input type="text" name="title"> <p class="style1">I hear by agree that the information I have provided is true, accurate and the information I am submitting is <br /> not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms:</p> <select name="agree" size="1"> <option value="Agree">Agree</option> <option value="Disagree">Disagree</option> </select> <br /> <br /> <p class="style1">Employee ID:</p> <input type="text" name="employee"> <br /> <input type="submit" value="Send"><input type="reset" value="Clear"> </div> </form> </p> The mailtest php is this ?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $name = $_POST['name']; $address = $_POST['address']; $email = $_POST['email']; $phone = $_POST['phone']; $debtor = $_POST['debtor']; $debtora = $_POST['debtora']; $value = $_POST['chk']; $pname = $_POST['pname']; $title = $_POST['title']; $agree = $_POST['agree']; $employee = $_POST['employee']; $formcontent=" From: $name \n Address: $address \n Email: $email \n Phone: $phone \n Debtor: $debtor \n Debtor's Address: $debtora \n 'Client' has read Assignment and Contract Agreement: $value \n Print Name: $pname \n Title: $title \n I hear by agree that the information I have provided is true, accurate and the information I am submitting is not fraudulent. Please click the agree button that you adhere to Commercial Recovery Authority Inc.'s terms: $agree \n \n Employee ID: $employee \n IP: $ip"; $recipient = "mail@crapower.com"; $subject = "Online Authorization Form 33.3%"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); echo "Thank You!" . " -" . "<a href='index.php' style='text-decoration:none;color:#ffcb00;'> Return Home</a>"; $ip = $_POST['visitoraddress'] ?> Hello, Iv written a small script in JS to add input boxes of the type file to the page.. My problem is when i use multiple of those input boxes and submit the form the $_FILES variable only reads 1 of those boxes.. This is the javascript im using: Code: [Select] function addImageBox() { var imageBoxes = document.getElementById("imageBoxes"); var tr = document.createElement("tr"); var td = document.createElement("td"); var td2 = document.createElement("td"); var inputFile = document.createElement("input"); inputFile.setAttribute("type", "file"); inputFile.setAttribute("name", "image[]"); inputFile.setAttribute("style", "width: 450px"); td.appendChild(document.createTextNode("Image")); td2.appendChild(inputFile); tr.appendChild(td); tr.appendChild(td2); imageBoxes.appendChild(tr); } When i add 2 boxes (making it 3 boxes on the page in total) and count the $_FILES var after submiting the form, the count method returns 1, and when i var_dump it only 1 array is in $_FILES. Any idea's? thanks! Hi, everyone. I need help with a PHP project on which I'm currently working. I need to create a form which does the following: 1) When you insert a negative number, it echoes: "Please insert a positive number." 2) When you insert a number greater than 1000, it echoes: "Please insert a number less than 1000." 3) When you insert anything else that's not a number (ie: a letter), it echoes: "Please insert a valid number." 4) If it doesn't do any of the above, it'll take the number that you entered and loop "Hello World" as many times as that number. The code that I have so far looks something like below. (I had to type it from the top of my head.) <?php <form action="hwpositive.php" method="post"> Enter number: <input type="text" name="number" /> </form> $input = $_POST["number"]; if ($input<0) { echo "Please insert a positive number."; } else if ($input>1000) { echo "Please insert a number less than 1000."; } else if ($input!=is_numeric) { echo "Please insert a valid number."; } else { for {$i; $i<=$_POST["number"]; $i++;} } ?> I can get this code to do the first three tasks listed above, but not the last. I'm a high school Programming 12 student, and this is my first year of learning PHP coding. Please help me out. Would it be better to use the case-switch option? I'm not too familiar on how to use it. Thank you in advance! I appreciate your help greatly. Whit my code it only appear a list of 1 or 0 and the id but I don't know how to get to show only the id Like so: submit 0 60/ 0 59/ 0 58/ 0 57/ 0 56/ 0 45/ 0 38/ 1 37/ on my first page: Code: [Select] <table border="2"> <tr> <th>Id</th> <th>User</th> <th>Comment</th> <th>Yes</th> <th>No</th> </tr> <form method="post" action="admincommentdelete.php" id="formc"> <?php $vv = array(); $st = Comment::test($result['article']->id,0,999); $vv['comment'] = $st['comment']; $i = 0; foreach($vv['comment'] as $p) { $i++; echo "<tr>"; echo "<td>".$p->id."</td>"; echo "<td>".$p->usern."</td>"; echo "<td>".$p->com."</td>"; echo "<td><input name=$i type=radio value='1'/></td>"; echo "<td><input name=$i type=radio value='0'/></td>"; echo "<input type=hidden name=h".$i." value=$p->id/>"; echo "</tr>"; } ?> <input type="submit" value="submit" name="submit"> </form> </table> second: Code: [Select] <?php $id = array(); if(isset($_POST['submit'])) { $data = array(); $data = $_POST; foreach($data as $key) { echo $key."</br>"; } } ?> Hello friends i need to make the following idea Code: [Select] <form method="post"> Enter ID : <input type="text" name="id" /> <input type="submit" value="Submit" /> </form> and the input id should goes to php code on same page as $id $ORGtext= file_get_contents('NewsID=$id'); how to write it correct thanks Hello Codingforums, yet again I desire some help to my coding, this time regarding a paypal button. Hello again. I need help for a PHP project I'm working on for school. I need it to do the following: 1) When nothing is entered, it will echo "Please enter a number." 2) When "0" is entered, it will echo "Please enter a number that is not zero." My code is as follows... <form action="hwpositive.php" method="post"> Enter number <input type="text" name="number"/><br /> </form> <?php $input = $_POST['number']; // if number entered is less than 0 if ($input<0) { echo "Enter a positive number."; } // if number entered is greated than 1000 elseif ($input>1000) { echo "Enter a number less than 1000."; } // if number entered is not a number (ie, a letter, a character) elseif (!is_numeric($input)) { echo "<br><img src=\"squidward.jpg\"><br><br>Enter a valid number. "; } // if number entered is between 1-999 elseif (($input>0) && ($input<1000)) { echo "hello world " . $i . "<br />"; } // if number entered is zero elseif ($input===0) { echo "Please enter a number that is not zero."; } // if no number is entered elseif ($input=null) { echo "Please enter a number."; } else { echo "Please enter a number."; } ?> However, it's not working. What am I doing wrong? Everytime I enter this page, it should show me "Please enter a number" because I haven't entered anything yet, but it doesn't. It's showing me the image right away. I don't understand... Help me, please! Thank you so much in advance. I appreciate the help. Hey Everyone, My website asks for an email address when one registers but I want to put a limit it on it (like to register you gotta have an email address from a specific domain). How can I edit the form input to do this? Any help will be greatly appreciated, thanks -STG I want to redirect my visitors to a certain page after validating their form input to be correct. I have 3 codes which are named code1, code2 and code 3. these are just 6 digit numbers. After a user has filled out the correct 3 codes I want to forward them to specific page but as of now I get no errors but the page that opens up is my handle_form.php which is the file that is only supposed to be validating the inputs. Here's is the code to the form: <form action="handle_form.php" method="post"> <div class="class6"> <b> <table border="1" width="500" height="60" bgcolor="#898989" bordercolor="black"> <tr> <td align="center" width="150"> <a href="/step1.php" target="_blank">Link 1</a> </td> <td align="center" width="150"> Code 1 </td> <td width="200" align="center"> <input type="text" name="code1" size="6"/> </td> </tr> <tr> <td align="center" width="150"> <a href="/step2.php" target="_blank">Link 2</a> </td> <td align="center" width="150"> Code 2 </td> <td width="200" align="center"> <input type="text" name="code2" size="6"/> </td> </tr> <tr> <td align="center" width="150"> <a href="/step3.php" target="_blank">Link 3</a> </td> <td align="center" width="150"> Code 3 </td> <td width="200" align="center"> <input type="text" name="code3" size="6"/> </td> </tr> </table></b><br> <input type="submit" name="submit" value="Take me to the Download Page"/> </div> </form> Now here is the code within the handle_form.php <?php if (isset($_POST['submitted'])) { $realcode1 = 723598; $realcode2 = 193598; $realcode3 = 887362; if (!empty($_POST['code1'])) { $code1 = escape_data (htmlspecialcharacters($_POST['code1'])); } else { echo '<p><font color="red"> You forgot to enter code1.</font></p>'; $code1 = FALSE; } if (!empty($_POST['code2'])) { $code2 = escape_data (htmlspecialcharacters($_POST['code2'])); } else { echo '<p><font color="red"> You forgot to enter code2.</font></p>'; $code2 = FALSE; } if (!empty($_POST['code3'])) { $code3 = escape_data (htmlspecialcharacters($_POST['code3'])); } else { echo '<p><font color="red"> You forgot to enter code1.</font></p>'; $code3 = FALSE; } if ($code1 = $realcode1 && $code2 = $realcode2 && $code3 = $realcode3) { $url .= '/software/Express_Paste.zip'; header('Location: $url'); } else { echo "You haven't entered the correct codes."; } } exit(); ?> When i submit the form using the correct data my handle_form.php page opens??? Where am I going wrong? I have a number of Forms which I want to control the input, for example prevent people from using numbers or ensure that people use specific characters. For example "Your password must contain a capital letter and at least one number". Does anyone know what code I should use to do this. hello all, i have a php form with multiple submits (one calculates price, one checks date and one submits the form and the data to mysql database) when i hit calculate price, for example, the function works fine but all the fields are cleared and i would like for all the input to remain as the user sent. here is part of the code (the form): Code: [Select] <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"> <fieldset> <legend ><span><a>video</span></a></legend> <ol> <li> <label for="hover_camera">hover camera</label> <input id="hover_camera" type="radio" name="hover_camera" value="yes" /><b>yes</b> <input id="hover_camera" type="radio" name="hover_camera" value="no" /><b>no</b> </li> <li> <label for="video_photographers">video photographers</label> <input id="video_photographers" type="text" name="video_photographers" maxlength="1" size="1"/> </li> <li> <label for="video_edit">video edit</label> <input id="video_edit" type="radio" name="video_edit" value="short" /><b>short</b> <input id="video_edit" type="radio" name="video_edit" value="long" /><b>long</b> </li> <li> <label for="video_clip">video clip</label> <select name="video_clip"> <option value="no">no</option> <option value="regular">regular</option> <option value="staged">staged</option> </select> </li> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>stills</span></a></legend> <ol> <li> <label for="stills">stills</label> <input id="stills" type="text" name="stills" maxlength="1" size="1" /> </li> <li> <label for="increase">increase amount</label> <input id="increase" type="text" name="increase" maxlength="4" size="1" /> </li> <li> <label for="magnets">magnets</label> <input id="magnets" type="text" name="magnets" maxlength="4" size="1" /> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>albums</span></a></legend> <ol> <li> <label for="digital_album">digital album</label> <input id="digital_album" type="radio" name="digital_album" value="yes" /><b>yes</b> <input id="digital_album" type="radio" name="digital_album" value="no" /><b>no</b> </li> <li> <label for="photo_album">photo album</label> <input id="photo_album" type="radio" name="photo_album" value="yes" /><b>yes</b> <input id="photo_album" type="radio" name="photo_album" value="no" /><b>no</b> </li> <li> <label for="small_digital_album">small digital album</label> <input id="small_digital_album" type="radio" name="small_digital_album" value="yes" /><b>yes</b> <input id="small_digital_album" type="radio" name="small_digital_album" value="no" /><b>no</b> </li> </ol> </fieldset><br /> <fieldset align="right"> <ol> <li> <label for="comments">comments</label> <textarea id="comments" name="comments"></textarea><br /><br /> </li> <li> <label for="price">price</label> <td><input type="submit" id = "price" name="price" value="calculate price" /></td> </li> </ol> </fieldset><br /> <fieldset align="right"> <legend><span><a>choose date</span></a></legend> <ol> <li> <input type="submit" id="isavailable" name="isavailable" value="isavailable" /> </li> </ol> </fieldset> <fieldset class="submit"> <ol> <li> <input class="submit" type="submit" id="submit" name="submit" value="done!" /> <input class="submit" type="reset" id="reset" name="reset" value="reset" /> </li> </ol> </fieldset> </form> thanks for the help |