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.
Related
I have a standard web page enclosed within a PHP form. Is there a way to save the entire contents of the form (HTML included) out as a it's own HTML file with the form answers included? The answers are either a drop-down selector or a standard text entry box.
I'd rather not have to generate a new HTML file with the responses if I can.
You can try to use javascript to capture the current html and responses of the form on submit, assign this code to a hidden form field and then submit the form. Having said that, I don't think this is a very reliable solution and also it really should'nt be so difficult to generate the same form with responses in php.
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 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.
Guys, im scratching my head around this one.
I have this website that basically contains a few forms that are filled in by the user. The user then can download that information in human readable format (pdf) or machine readable format (xml) but I'm having a slight problem submitting textboxes.
I have a few of them, for instance in the description section, but when i access the $_POST['Desc_Desc_desc'] value, it's empty even though i can see content on the textarea. The weird thing is that when i use firebug to inspect the element, it shows the element as if it had no contents..
Can anyone figure what is causing this strange behavior?
In service_level_library.buttons.prepForSubmit, the textarea is cloned along with the rest of the form via the DOM cloneNode method. This copies HTML element attributes, but not DOM properties. (Sometimes DOM element node properties have a corresponding attribute, so updating the property affects the attribute, which can make it appear that DOM properties are being copied.)
While textarea DOM objects have a value property, the textarea HTML element doesn't have a corresponding value attribute, so the value property isn't exposing an attribute. Thus when you clone the node, the (empty) value attribute is what gets copied, leaving the current value of the element (as accessible via the value property) behind.
To fix your script, do one of:
Copy the value after cloning.
Set the initial value for the textarea, either by assigning to the defaultValue property or setting the text content of the node, before cloning. This works because the current value of the cloned node will be set to its initial value, and a deep copy of a textarea will copy its text contents (the source of its initial value).
Programmatically replace the textarea with an input before cloning (though this would be more involved than the other options),
You say in your question $_POST['Desc_Desc_desc'], although in the code I see a textarea with name Dep_desc and id Dep_Desc_Desc. Then you should write $_POST['Dep_desc'], i.e. the name of the <textarea> instead of the id.
Also, textareas don't have a value attribute, so in your html you should write the initial content between the opening and the closing tag.
HTML
<textarea name="Dep_desc" id="Dep_Desc_Desc">Initial content</textarea>
PHP
echo "The content of the textarea is ".nl2br(htmlspecialchars($_POST['Dep_desc']));
notes
nl2br: Respect new lines in the html output replacing the \n symbol with <br />.
htmlspecialchars: Prevent possible XSS attacks.
I used firebug to analyze what gets sent to your script by
document.getElementById('descriptionForm').submit()
The form data is being sent correctly
Content-Type: application/x-www-form-urlencoded Content-Length: 113
Desc_Desc_name=SO&Desc_Desc_keywords=overflow&Desc_Desc_concept=http%3A%2F%2Fso.com&Desc_Desc_desc=Stack+overflow
The form action parameter is currently set to "submit.action" which yields a 404.
The form buttons are defined outside your form tag.
The form buttons does not activate a submit on your form.
Bottom line: the form does not get submitted to the intended recipient.
I had a similar issue but later I found out that somewhere at the bottom, I had reused the same name for another element which was empty. That wiped off my required element at var_dump, print_r as well. It took a while to get that out.