0

hie there, is there any way i can use input button as submit button for a form ?
I know about Submit button but wanted to make input button work like submit button.

Thanx

3
Contributors
12
Replies
34
Views
4 Years
Discussion Span
Last Post by Rahul47
Featured Replies
  • 2

    Ok, now I completely understand what you are asking. Yes it can be done, but you need help from JavaScript. Paulkd mentioned it in his response. Here is an example of how to use an input element of type "button" to submit a form: <!DOCTYPE html> <html> <head> <script> function … Read More

0

<input type="submit"... is actually the normal "submit" button.

I am looking for an alternative way.

0

Yes but you asked if you can use the input element as a submit button. The answer is yes. Are we missing something about the question?

0

Using JavaScript you can practically use any element to submit a form.

I think the <button> tag might also submit without JavaScript.

Also, pressing the enter key in an input text field will submit a form without the need for a button :-)

Edited by paulkd: update

0

Yes but you asked if you can use the input element as a submit button. The answer is yes. Are we missing something about the question?

I have mentioned in question that I am aware of <input type="submit" >. I wanted to make <input type="button"> work like submit button.

Using submit button will cause data in input fields to be stored in $_POST associative array. Is there any way to achieve the same using simple button ?

Edited by Rahul47: mistakes

2

Ok, now I completely understand what you are asking. Yes it can be done, but you need help from JavaScript. Paulkd mentioned it in his response.

Here is an example of how to use an input element of type "button" to submit a form:

<!DOCTYPE html>
<html>
<head>
 <script>
   function formSubmit(){ document.getElementById("form1").submit(); }
 </script>
</head>
<body>
<form id="form1" action="formPage.php">
 Name: <input type="text" name="textBox1"><br />
 <input type="button" onclick="formSubmit()" value="Submit" />
</form>

</body>
</html>
0

@paulkd: The prime question here is how data will be transfered to php script ? i.e to $_POST associative array .

0

I added a php script and modified filename. Rest all is as it was and executed it . Following is code and snap of first execution that follows.

<!DOCTYPE html>
<html>
<head>
 <script>
   function formSubmit()
    { 
        document.getElementById("form1").submit();
     }
 </script>
</head>
<body>
<form id="form1" action="test.php" method="POST">
 Name: <input type="text" name="name" ><br/>
 <input type="button" onclick="formSubmit()" value="Submit" />
</form>

<?php
$name1=$_POST['name'];
echo "<br> Your name is $name1 . Thanks for using our system.";
?>

</body>
</html>

646873bfde244ce6f2863194d3bb87ae

Any idea why that error might be screaming ?

After entering name it executes well.
12c89afc69b81e1bf9ac7e573674229b

Edited by Rahul47: mistakes

0

@paulkd: Well the question is solved. I wanted to make simple button work as Submit button which was done with help of above Javascript.

Can you point out why I might be getting that error message in above script ?

0

Rahul47,

lines 17-20 should be in test.php. All the other code should be in another file e.g. index.php

0

lines 17-20 should be in test.php. All the other code should be in another file e.g. index.php

Well the file itself is test.php. And my friend problem is solved.
You can see this to clear why that error was screaming.

Thanx for your help paulkd, hope to see your help in future threads too.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.