I have a form that I generate new input fields to with javascript and the generated fields won't post.
I have made a demo which I stripped the database etc. because it might not have been secure (for injections) which var_dumps POST
http://resk.latvalashop.com/test.php
Try to fill in everything and press a couple times the "+" button to add a couple of rows, fill them and then press "Tallenna" which will POST the form.
the problem is the floating element to right of the main element, the first fields are not generated by javascript and POST as they should, but if you press the "+" and try to post from the newly created forms nothing will be POSTed.
Any help appriciated!
The generated input elemnts are not contained inside of an <form> element, so they are not able to be posted. You should push your <form action="result.php" ... > higher up in the DOM hierarchy.
I think your problem is in your HTML.
The level where you open your <form> element (3 <div>'s deep) isn't the same as where you close it (2 <div>'s deep). That will probably fix it.
You have to wrap those with <form></form> tags.
Related
i have a <form> in the first view and </form> in the last view.
Looking at the DOM i can see that form tag is being closed in the final of the first view and i am only getting the input data of the first view.
enter image description here
I´ve tried putting <form> as first and last tags of my frontend code but then the request don´t work.
PD. Sorry for my english.
I am working with laravel.
Thanks.
All tags may contains another tags but never contain a lot of codes from tag. This is not sense.
If you want to form for multiple view, please use form in layout file not in 1-2-3 files
Ok, so the weirdest thing happened here.
I have a php file with Javascript to write onto elements based on events on the webpage.
And there are 3 html forms on the page. One is a searchbox, one has all inputs hidden and gets submitted on a certain event, and one is a textbox and a button on clicking which the javascript writes the text to a certain element in the page.
Also, this third form is itself written onto the document by the javascript on clicking another button.
The problem is, while doing certain operations with this third form, i need to reference one of its inputs values (newSkillName).
So for this third form, In Chrome-
document.forms[1].newSkillName.value
works,
while in Firefox-
document.forms[2].newSkillName.value
works.
I, however, managed to fix the code. But i'm still curious. Why did Chrome and Firefox process the abnormality differently?? Any idea?
Give the form elements unique ID attributes and reference them with document.getElementById(id).
You could also use the NAME attribute and reference the form by name document.forms["name_of_form"];
The quick workaround/copout fix is to hunt down the field in the DOM a diffferent way. For example, with id='NewSkillName' use document.getElementById('NewSkillName').value.
I am new to html, I would be really glad if you can help me with this.
I have a web page where there is a list and some other text inputs and buttons. This option list can be populated by clicking the "add" button in the page, this add button is to direct to another page and in that page there are some chekboxes, those which are checked are loaded back to the main page,(where I have the list) .
At the end data in the main page needs to be loaded to the database, (what is in the list and in the text inputs).
Since I'm new I just know little about php and html, I thought I should have a form within a another form(form to "add items", form to load to the database) and it is not possible in html. Can anyone suggest the best way to do this? Do I need to use javascript?
Why can't the extra inputs (the ones that would be in the second form) be part of the first form? I think the question will become clearer if you post a sample form so we can see the relationship between the two forms.
But overall, since you're ultimately only submitting one form, then maybe all the inputs belong together. If what you're calling the second form isn't supposed to be visible right away, you can still have it be part of the same form, but only reveal it when needed.
Again, some sample data would help to understand the exact context of your question.
in php if you use input name="somename[]"
for a number of input elems
you will get an array in $_POST['somename'] and access all the values.
I think what you're after - if I understand you correctly - is ajax. Ajax allows you to asynchronously send data to/from another script without leaving the current page. This is accomplished using JavaScript. In your case I think what you need to do is set an onclick event in JavaScript to a button:
<input type="button" onclick="javascriptFunction()">
You can read more about ajax here:
http://www.tizag.com/ajaxTutorial/ajaxform.php
I have a form that has a <textarea> that I would like to replace with a <div contenteditable="true". Is there an easy way to insert that content into my MySQL database with PHP?
I just implemented this, so I don't know what bugs there are right now, but it does work. I also know that it's pretty hacked together and there is probably a more elegant solution to doing this, but this one works.
I'm making a simple assumptions here: Your textarea contains html elements in it and doesn't mess up your database (using whatever method you like best)
Community Wiki'd because it's something that other people might have better ideas on.
First convert your textareas to divs, don't add extra space between the div and the content (it should be like this: <div id="content" contenteditable="true"><p>First paragraph...
Pick an id for each div that's going to now be contenteditable, on my site I've decided on the really simple content id, and I only have one div that's editable on each page that needs editing (you might need more. Each div needs it's own id).
Make a form, AFTER (or before, just don't put your div inside of the form, actually, that probably doesn't matter, but just to be safe), put a hidden textarea (display:none; visibility:none) with no content.
Add a hidden input field that contains a unique identifier for your database's reference to the current page.
Place a submit button OUTSIDE of the form. This is done because you're going to call a javascript function to put your div's content into the hidden textarea and submit the form after that.
Add an onclick attribute to the submit button, have it call the function to update (mine's upport because it updates my portfolio)
Make the function.
Create a new variable that contains the div's content (var nt = document.getElementById('contentId').innerHTML;)
Add that content to the hidden textarea (document.forms["formId"].nameOfTextarea.value += nt;)
Submit the form (document.forms["upport"].submit();)
Now make the form processor the way you normally would.
I have a form that has cloned form elements in it. The form submits to e-mail. The problem I am having is that when a user lets say changes their mind and removes a cloned form element block and submits the form, the cloned form element that they removed shows up in the email output. How can I get it so that removed element(s) do not show up in the e-mail output?
The form is here: http://www.pentco.com/test.php
I've duplicated and commented out the php code that's used to process the form at the beginning of the page source so that it remains visible when viewing the source and does not get compiled.
Any illumination is greatly appreciated.
That is because your javascript for Removing the item is only hiding the element - not removing it. This keeps all the form elements within the document and allows them to be submitted.
As Chris pointed out, you are .hide()-ing an element, when you really should .remove() it.