PHP form does not submit [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to submit the form after an if statement for example:
<?Php
if($something){
?>
<script type="text/javascript">
document.getElementById('dateForm').submit(); // SUBMIT FORM
</script>
<form id="dateForm" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="test" value="test">
<input type="hidden" name"test2" value="Support">
</form>
<?php
}
?>
However, this doesn't work.

Put the script after the form tag. It searches dateForm id and until that no form is in the output so it does nothing. When you place that after it, it'll search the page for that id and it finds that and submits.
<?Php
if($something):?>
<form id="dateForm" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="test" value="test">
<input type="hidden" name"test2" value="Support">
</form>
<script type="text/javascript">
document.getElementById('dateForm').submit(); // SUBMIT FORM
</script>
<?php
endif;?>

Related

Creating an HTML form to interact with REST API [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I am trying to write an HTML form to interact with a REST API.
This is what I have so far, but I'm not sure what I need to do to actually get it to interact with the REST API, how do I link them?
<!DOCTYPE html>
</html>
<head>
</head>
<body>
<form id="myForm">
<label for="name">Name</label><br>
<input type="text" id="name" name="name"><br>
<label for="password">Password</label><br>
<input type="text" id="password" name="password"><br>
</form>
</body>
You are almost there. First of all, your form needs to be submittable. You can achieve this by adding a submit input:
<!DOCTYPE html>
</html>
<head>
</head>
<body>
<form id="myForm" action="/action_page.php">
<label for="name">Name</label><br>
<input type="text" id="name" name="name"><br>
<label for="password">Password</label><br>
<input type="text" id="password" name="password"><br>
<input type="submit" value="Submit">
</form>
</body>
Now, your structure is ready to be used. On the other end, you have a RESTful API, which should handle properly the request your form is sending. You can achieve that using the action attribute of your form tag.

Add input into form with jquery and submit [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to add an input into form using JQuery, and then submit the form with pure HTML without using javascript.
<form method="post" action="" id="myform" >
<input type="hidden" name="example" value="done" />
<input type="submit" value="try" />
</form>
Here my JQuery line that add new input:
$('#myform').append("<input name="example2" value="done" type='hidden'/>");
My issue is when i submit the form, i can't get example2 input value ! help me to figure it out.
What you need to do is download jquery library or use the external google cdn library as the one i have used in my case in the head of your html file.
Ensure that you append the input on the form as the document loads.
If you intend to submit your form to Php as the server side check if the form is posted and print the output.
You should save your file with .php extension.
Try the solution below.
Thanks
$(document).ready(function() {
$("form#myform").append("<input name='example2' value='done' type='hidden'/>")
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form method="post" action="" id="myform">
<input type="hidden" name="example" value="done" />
<input type="submit" value="try" />
</form>
Seems like the input box failed to append at the end of the form.
You could try inspect element and check if the HTML for the hidden field is generated. Check the quotes:
$('#myform').append('<input name="example2" value="done" type="hidden"/>');
Your JQuery appears to use double quotes when single should be used:
$('#myform').append("<input name='example2' value='done' type='hidden'/>");
if you use "" at the start and at the end of the () , inside use '' . same if you use '' at the start and at the end of the () ,inside use ""
see more here : When to use double or single quotes in JavaScript?
or here : Single or Double quotes in jQuery
$('#myform').append("<input name='example2' value='done' type='hidden'>");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="post" action="" id="myform" >
<input type="hidden" name="example" value="done" />
<input type="submit" value="try" />
</form>
What you need to do is download jQuery library or use the external google CDN library as the one I have used in my case in the head of your html file.
Ensure that you append the input on the form as the document loads.
If you intend to submit your form to PHP as the server side check if the form is posted and print the output. You should save your file with .php extension.
Try the solution below.
$(document).ready(function() {
$("form#myform").append("<input name='example2' value='done' type='hidden'/>")
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<form method="post" action="" id="myform">
<input type="hidden" name="example" value="done" />
<input type="submit" value="try" />
</form>

Php : cant sumbit the good form [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Sorry for my spelling
Hi, im trying to make a website showing internet forfeit, so in mySQL database i put all my information then I print it on my web page, the the user click on the forfeit he wants, it brings him to an other page that shows all the forfeit informations... In the while(), I'm making unique form for each forfeit, then on the
The problem here is that the only form sumbitted is the last one created
include_once "DataBase/db.php";
if($internet->num_rows != 0){
while($rows = $internet->fetch_assoc()){
$nom = $rows["nom"];
$id = $rows["id"];
$tech = $rows["technologie"];
$telechargement = $rows["telechargement"];
$televersement = $rows["televersement"];
$utilisation = $rows["utilisation"];
$prix= $rows["prix"];
echo '
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
<div class="boxes">
<div class="[ price-option price-option--high ]">
<div class="price-option__detail">
<span class="price-option__cost">'.$nom.'<br>$'.$prix.'</span>
</div>
<input type="hidden" name="id" value="'.$id.'"></input>
<input type="hidden" name="nom" value="'.$nom.'"></input>
<input type="hidden" name="tech" value="'.$tech.'"></input>
<input type="hidden" name="telechargement" value="'.$telechargement.'"></input>
<input type="hidden" name="televersement" value="'.$televersement.'"></input>
<input type="hidden" name="utilisation" value="'.$utilisation.'"></input>
<input type="hidden" name="prix" value="'.$prix.'"></input>
<div class="price-option__purchase">
Submit
</div>
</div>
</div>
';
}
}
You can see what i'm talking about here : http://fournisseursquebec.com/Forfaits.php
just select internet
Thank you!
You are missing the closing </form> tag for every box. Now you have one big form with a lot of repeated fields:
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
box 1:
<input type="hidden" name="id" value="'.$id.'"></input>
.... box 2:
<input type="hidden" name="id" value="'.$id.'"></input>
...
The name attribute of the various input is the one that is sent and should be unique inside every form.
Just add the </form> tag in your while loop and it should work.

How to put values of textbox into variable in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to add values to my MySql database using PHP. The values I want to add, will come from the text-boxes of a form. I tried $variable = $_POST['formElementName'] and used $variable to insert values. But it doesn't work.
Question:
How can I put the values of the text-boxes into variables?
Thanks.
Use below code for the form
<form name="form-name" action="" method="POST">
<input type="text" name="fieldname1" value="" />
<input type="text" name="fieldname2" value="" />
</form>
and for php manipulation at server end, you will get values in $_POST i.e.
$_POST['fieldname1'] and $_POST['fieldname2]
I just want to elaborate what #Kyle wrote
Note: The form method is POST
HTML part
<form action="your_php_file_name.php" method="POST">
<input type="text" name="first_name" />
<input type="submit" value="Submit" />
</form>
PHP part: The file name is: your_php_file_name.php
<?php
//A good practice to check the type of HTTP request
$fname = $_POST['first_name'];
?>
Some good practices
Check the HTTP request type sent from the client side. (I find it a good way)
Sanitize the variables before inserting.
Here's an idea:
Client-side:
<input type="text" name="first_name">
Server-side:
$var = $_POST["first_name"];
Just to add to Kyle's answer above, Make sure you have value="Something" set, otherwise it will return nothing.
<input type="text" name="first_name" value="Testing">
Server Side
$var = $_POST["first_name"];
For debugging I use:
print_r($_POST)
This will return all the POST values set and is really handy.

Submitting a form without page reload [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I don't know Ajax or PHP but I want to submit this form without page refresh and also want to appear check icon beside the submit button. How can I do this?
<form id="form" action="" method="post">
<input type="text" id="email" value="e-mail address" />
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
<script>
function xyz(){
var email_val=$('#email').val();
$.post("ajax.php",{"email":email_val},function(data){
if(data) {
$('#message').html('Data submit successfully');
$('#email').val('');
}
else{
$('#message').html('Failed');
}
});
}
</script>
<form id="form" action="" method="post" onsubmit="xyz()">
<input type="text" id="email" value="e-mail address" />
<input type="submit" id="submit" name="submit" value="Submit" />
<span id="message"></span>
</form>
ajax.php
if(isset($_REQUEST['email'])){
//Your code here
}
If you are not aware of AJAX and PHP but still you have to submit a form without page reload then follow this tutorial.. do some home works
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

Categories

Resources