I have a food recipes site, users are able to submit their own recipes, on the page where you submit your recipes there are textboxes to enter the description of the recipe.
What I need is basically, when users open the page with the form, on the textbox I want to appear a table there (I already have the code for the table). I just don't know where to put that code. I was wondering if I could use value="table code here" for the table to appear in the text box? Or is there another way?
Here's the code of the textbox:
<label for="inputPassword3" class="col-sm-3 control-label"><?php echo RECIPE_DESCRIPTION; ?></label>
The tag does not allow you to pass in a tag. What I would recommend however is creating a and adding tags inside of your individual table row's cells.
Ex:
<table>
<tr><td><input type="text" /></td></tr>
</table>
Related
edit: Somebody in the answers recommended a list, and I think that that is a good idea, but then I have no idea of how to implement that with the amount as well as the type. So if someone could explain that?
I have to make a fast food order form for school, and I decided to make you able to enter the amount as an input instead of checkboxes, but I still want them stored in an array. Is there any way to do that? Here's a little snippet of what I have in html:
<form>
<table class="menu" style="width:100%;">
<tr>
<td class="productlist">
<!-- Drinks -->
<input type="number" name="drinks[]" value="cokeclassic" id="cokeclassic" class="productCheckBox" min="0" max="20" placeholder="0">
<label for="cokeclassic" class="product">Coca Cola Classic $0.75<br><br></label>
</tr>
</table>
<input type="submit" value="Cart" class="submit">
</form>
If you want them stored in an array, you would need to have multiple input fields with name="drinks[]". All of your inputs will be sent as one array called drinks, containing numbers passed in each field.
If you want to pass name of a drink and an amount of it, you would need something like name="drinks[0].name" for name of your drink and name="drinks[0].amount" for amount
Why you would like to store them in an array?
When submitting the form, the input-tag can only deliver a single value anyways, because there is only a single input.
Try to do a list/stack with the orders or even try to create a dynamic multiselect including amounts when ordering.
I have a SQL Database where the users can create a ticket then update the ticket if need be. This all works and the user can view the updated field in the , but what I would to achieve is to display the newly updated field in a different textarea field but not be able to edit it and only edit a new textarea field. Once saved and the user needs to update it again it needs to then display the 2 uneditable textfields and display new textfield to update.
Here is my code what i have at the moment:
<div class="form-group col-lg-12 col-md-12 col-sm-12 <?php echo (!empty($description_err)) ? 'has-error' : ''; ?>">
<label>Description</label>
<textarea name="descriptionfield" class="form-control" required="required" placeholder="Enter Description"><?php echo $description; ?></textarea>
</div>
So with this code I can update and delete but only displays in the same textarea.
Can someone point me in the right direction to achieve this?
Hoping what I explained makes sense.
Thanks
Something like the below image
So you are only able to update and delete a textarea but you want to show the original one and a new empty text area after they submit, then if they update that one, the original one and second one show all while allowing a new textfield to be there?
You aren't creating the text-boxes, submitting queries, and fetching results in a way the allows you to do that.
What you need to do is:
In your general application you will need 2 things, the empty text area field for the which you already have. An empty div area where you could display the old text areas.
In your database you need to add another table because you you will basically be joining these child text area updates updates. new table: textareachildren.
When somebody submits a ticket, that text area information should go into your first table where the info is going which is already happening. Now I'm assuming your table for those posts has a primary ID correct? so lets say we just put a ticket in and the ID is 1. Here is where #Padmanabhan is trying to find out, when the ticket is submitted the page is refreshed correct? and it shows that ticket they just submitted?
Now they want to edit that ticket's text area, I assume you already are pulling in the ticket by it's ID. Since you said they could already edit/update but it just shows the value they submitted. It looks by your picture that theres a note added and new note section. OK so thats good, so within that function where they could update the ticket text area field, a few important things need to happen. Once they click update, you need to run a sql query to input this new textarea value into the textareachildren table. within that table there should be 3 columns, the primary ID of the new items in there, the value of the textarea field, and third the important the connecting_ID which is the same value of the ID of the original ticket ID. this is how they will be connected and you could display those historical text areas.
Now go back to your original query that displays the ticket when they first submit, in there you need to also query by joining the the original ticket id with the connecting_ID of the new child textarea. The query will say ah yes, I am pulling this textarea value from the other table because my connecting_ID is 1 and it matches my 'parents' so I know I belong to them. Then just display that in the html within a new text area field that does not have the option to update/edit, since its probably a for loop for all those children that you want to show, you could add in the HTML textarea disabled readonly attributes, and even add classes to it so its like grayed out or something that shows you can't edit.
So to summarize every time somebody updates the text field you aren't changing that original value since you want to display that, you just add this new child textarea field value in a new table, when you query to show those old values to you just join them and display those historical textareas how ever you want.
I have a html form with about 280 text, radios and select dropdown fields. I have to capture a lot of information about people's outgoings. Eg. Who their gas and electricity providers are, how much they pay, the rates, their bank accounts, loan accounts, broadband etc. The list of fields sounds huge, but it's laid out in tabs and it isn't too overwhelming and people don't have to fill in all of it anyway.
I present the blank form to the new user and then post every field value (blank or not) to the mysql dbase on the first submit.
The problem is.. how do I retrieve all that data and put it into the form the next time? I'm out of my depth with elegant solutions, so I guess I'd do a foreach loop through each database record retrieved and save it to a variable, but then I have to insert the 280 field values into the fields using an statement in the value="xxx" for each field, something like:
<div class="form-group row">
<label for="loan1name" class="col-lg-5 control-label text-right">Loan Name</label>
<div class="col-lg-3">
<input type="text" class="form-control" name="loan1name" placeholder="Car loan" value=<?php echo htmlspecialchars($loan1name) ?>>
</div>
</div>
If I had 10 fields it wouldn't matter, but 280 is unmanageable doing it that way. Is there any other way? Do I need to go about this a completely different way? Does it make sense to duplicate the form and use one for the blank one which does the INSERT, then another for the pre-populated version for the UPDATE query? Any help would be greatly appreciated. I just know there must be a better way, but I can't find any answer on here or anywhere else.
It doesn't seem simple because the fields are quite varied and one is even a set of pictures as a radio button sequence (it's pictures of types of locks you have on your front door - for your home insurance).
Mysql usually return an associative array. You can then use the key/value pairs in this array to dynamically create your form.
<?php foreach($fields AS $name => $value){ ?>
<input type="text" name="<?= $name ?>" value="<?= $value ?>" /><br />
<?php } ?>
Note: The downside is that you are still missing the label and placeholder of each input. Also, they would all be text input.
I have a page where a user can create a recipe. I have a javascript script that allows the user to keep adding form input elements for more ingredients. Say the recipe has 4 ingredients the user can continue to add inputs. However this changes the id to ingredient1/2/3/4 for the input ID/Name,and i can't understand how to get around getting the information from the form post as the amount of elements is upto user discretion. How would you go about loading the results into PHP variables and then inserting them into a mysql query.
the syntax for the html form
<div id="ingredient1" class="clonedInput">
<h2 class="first-column">Ingredient</h2>
<span style="float:left; padding-right: 10px;">
<input type="text" name="scroll" value="Add Ingredient" id="ingredient" class="ingredient"/>
</span>
</div>
ingredient1 would change to ingredient2 for the purpose 2 ingredient's being added.
A slightly confusing problem, so any help would be amazing!
JB
I think what you are looking for is using [] in your input element names. This will post the data as an array. So, say you have this as your form's ingredient input elements (after javascript has added several):
<input type="text" name="ingredients[]" value="" />
<input type="text" name="ingredients[]" value="" />
<input type="text" name="ingredients[]" value="" />
<input type="text" name="ingredients[]" value="" />
<input type="text" name="ingredients[]" value="" />
When the user POST's the data, you will be able to access the array of ingredients at $_POST['ingredients']
I will tell you the logic, not the code as only javascript here would not be enough.
you create a table ingredients. Anything you can allow them to use. id, ecc
while posting, instead of doing giving the user a freedom chosing their ingredient1, ingredient2 ... you do load from ingredients table the values and index them as ingredient[id_from_db] ecc..
you create a table recipe. It should have a unique id, its description
you create a relation table recipe_id, ingredient_id
then when the user post its data you create 1 row in the recipe and as many rows in the relation table as the ingredients they use.
When selecting later the recipe you also select everything which is in the relation table, it could be several rows there...
Hope it is of any help for you. Can't show you any code for this, but it is not hard to make if you understand how it goes.
maxim
My situation is this: I have an html page which contains a table of four rows and three columns. When creating the page (using a PHP script) some of the rows have their cells filled with text while the rest have their cells filled with text boxes. What I want to do is allow the user to fill any number of the rows with text boxes and then submit them to a PHP script.
When the user clicks submit, I want to get all the rows which the user has filled in (essentially the rows with filled textboxes) and submit just the data in those text boxes to the script, ideally in a 2D array where each row of the array represents a row of the table?
Well, you can echo out the input tags with the name attribute that goes something like fields[]. When submitted this will set $_POST['fields'] to an array containing the data given from the user.
HTML
<tr>
<td><input type="text" name="fields[]" /></td>
<td><input type="text" name="fields[]" /></td>
<td><input type="text" name="fields[]" /></td>
</tr>
PHP
var_dump($_POST['fields']); // User submitted data
I would name each cell as cell<column number>$<row number> then all you do in the PHP script is to check all the possible entries and find out if they have been sent to the server and use the data as appropriate.