Hey im making a website were you can send other users emails.
My problem is when I go and submit it doesn't submit both values?
my Form has a text box where the user wants to send the email and another is a text area which is the message.
and i don't want 2 submit buttons
Have a look at http://www.w3.org/TR/html401/interact/forms.html#h-17.1 on how to create forms.
Your inputs need unique name attributes.
Example:
<form>
<input type="text" name="recipient_address" />
<textarea name="message_body"></textarea>
<!-- no real need for a name on the submit button -->
<input type="submit" value="Send Message" />
</form>
any value that you want to send to the server make sure it is in the form tag. When the user clicks your "submit" button all of the data in the form is sent off along with the page request. You can have as many items as you want in the form.
<html>
<head>
/*... your code here
...*/
</head>
<body>
<form name='sampleForm' action='sample.htm' onsubmit='ValidatethisForm()' method="post" enctype="multipart/form-data">
<input type='text' name='formElem1'>
<textarea name='formElem2'></textarea>
<input type = 'submit' value='submit'>
</form>
</body>
</html>
In the validate function once u finish your validations use "return true" to proceed. You can submit multiple form elements as long as they have different name attributes and the are within your form tag.
By far the best I have found is here
Happy Coding
Check your input and add a unique name attribute.
Related
I want to submit a form to the database and I want to use a sprite image instead of regular submit buttons..
Here is the images I'm using
<div class="cancel">
</div>
<div class="save_and_new">
</div>
<div class="save_and_quit">
</div>
if(isset(......)){
}
I have no idea what to put in the isset function ...
Do i need to set names to the images? or what?
You could just use
<input type="image src="/your/button/image/here.gif" />
instead of the images nested inside anchors.
The only problem would be that you can't directly sense which button exactly was pressed because <input type="image" /> does not post a value. If you really need multiple post buttons that also post a value:
<button name="button" value="action1"><img src="/your/image/here.gif" alt="action 1" /></button>
<button name="button" value="action2"><img src="/your/image/here.gif" alt="action 2" /></button>
You can do it in Jquery. Try this,
$("#save_and_new_btn").click(function() {
$("#form").submit();
});
#form is id of form
Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript.
JavaScript provides the form object that contains the submit() method. Use the ‘id’ of the form to get the form object.
For example, if the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms["myform"].submit();
But, how to identify a form? Give an id attribute in the form tag
<form id='myform' action='formmail.pl'>
Here is the code to submit a form when a hyperlink is clicked:
<form name="myform" action="handle-data.php">
Search: <input type='text' name='query' />
Search
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>
Source: How to Submit a Form Using JavaScript
You need to use javascript.
Find a form which has to be submitted. Then add actions to each elements. Whene they're clicked you are submitting (or canceling) form.
<html>
<input name='name'>
<input name='handphone'>
</html>
I need some script to make if user type on name and their 'handphone' data that store on db will show on second input form
example if done
<form>
<input name='name' value='surya'>
<input name='handphone' value='081392111098'>
</form>
I think you need that if Any User type name input and if name is in database then headphone input autofill from database. For this You have to Use ajax or jQuery.
thanks
I'm a noobie programmer and I wonder how to properly submit a form with javascript.
I made some test code to show you what I mean:
<?php
if (isset($_POST['message']))
{
echo $_POST['message'];
}
?>
<script>
function formsubmit()
{
document.getElementById('form').submit();
}
</script>
<form id="form" name="form" action="" method="post">
<input id="message" name="message" value="hello world">
<input id="submit" name="submit" type="submit">
</form>
Click me<br/>
<input type="submit" onClick="formsubmit()" value="Click me">
When you push the "submit" button inside the tags - the php code will echo "hello world".
When submitting the form with JS the values won't post to the page. What am I doing wrong?
Thanks in advance.
I've searched the whole afternoon for a solution, but cause of my lack of knowledge about programming I failed to find it.
Believe it or not, but the main problem lies here:
<input id="submit" name="submit" type="submit">
If a form contains an input element with name (or id) of submit it will mask the .submit() method of the form element, because .submit will point to the button instead of the method. Just change it to this:
<input name="go" type="submit">
See also: Notes for form.submit()
The smaller problem is here:
Click me<br/>
An empty anchor will just request the same page again before calling formsubmit(). Just add href="#".
The problem here is that the id and name of the input element on your form is called submit.
This will mask the submit function for the form. Change the name and id and you will be able to use javascript to submit the form.
try setting the href of the to '#'. I would guess what is happening is that by clicking on the link, it submits the form and immediately changes the url to the same page you are on cancelling the form submit before it has a chance to go.
Hello I have a form working properly using
php echo $_SERVER['PHP_SELF']
The results are shown on same page as form.
I need to be able to send the form data and results to another page (eg results.php) when the user submits the form.
How is this achieved?
Just point the form action to results.php
<form action="results.php">
<!--Inputs-->
</form>
Or if you need to do a redirection store $_GET at $_SESSION['parameters'] .
Here are some attributes of form tag <form> you need to set them..
<form action="controller.php" method="post">
<!--form elements-->
<input type="submit" name="submit" value="Submit Form" />
</form>
Here when ever the submit button clicked, it will submit the form to its action i.e. controller.php by post method (i.e. form elements' value won't display in query string).
Later you can access their value on controller.php by $_REQUEST['element_name'] or $_POST['element_name'] or $_GET['element_name'] according to the form method type.
I have a page that displays a photo the user has uploaded. I have two forms that provide two different actions. The first form, replace_photo_form, is simply a button that the user pushes to replace the photo. The second form, next_page_form, is a field to enter the caption for the photo as well as a button to proceed to the next page. When the user pushes the next_page button, it should save the caption to the DB and continue to the next page.
<body>
<form id="replace_photo_form">
<input type="text" name="caption" />
<input type="submit" name="replace_photo" value="Replace Photo" />
</form>
<div>
<p>This is where some other information is located</p>
</div>
<form id="next_page_form">
<input type="submit" name="next_page" value="Next Page" />
</form>
</body>
I want the caption field to appear directly next to the replace_photo button in the page structure so I included it in the replace_photo_form. The problem is that when I push the next_page button, it doesn't save the POST value for the caption input field as I would like. Ideally I would just include the caption field in the next_page_form so I saves the caption as a POST value, but I need it to appear next to the replace photo button.
How can I include a form field in my POST if it is not in the current form?
Merge the two forms into one that spans both submit buttons (it will still include the input of course).
Then, when the form is submitted, you can check which of the values (next_page or replace_photo) exists in $_POST, therefore discovering which button was pressed and what action you need to take.
This technique will work correctly even if Javascript is disabled. If you are willing to relax this restriction, there are dozens of other options (e.g. hooking the submit event of a form to copy the value of the text box from another form in a hidden field of the current form).
One possibility is to add a listener to the field that ties its value to a hidden field in the second form:
<form id="replace_photo_form">
<input type="text" name="caption"
onchange="document.getElementById('next_page_form_caption').value = this.value;"/>
..
</form
<form id="next_page_form">
<input type="hidden" id="next_page_form_caption" name="caption"/>
..
</form>
You mean replace_photo_form submit before next_page button clicked, you can simply add an onclick to next_page button, like this:
<input type="submit" name="next_page" value="Next Page" onclick="document.getElementById("replace_photo_form").submit();" />