i've got a problem with the load Methode from jQuery.
Here my code:
$('#form').submit(function( event ) {
$('.response').load('responseData.php?'+
$('#form').serialize());
event.preventDefault();
});
<form id="form">
<input type="text" name="title" id="title" />
<input type="text" name="text" id="text" /><br>
<input type="submit" value="Speichern" class="submit"/>
</form>
<div class="response"></div>
The file responseData.php exists. But when I click submit, i get an '500 internal error'.
The path is correct it is:
http://domain.de/data/responseData.php?title=test&text=test
Do you know what's going on here? I'm really desperated.
Thank you!
Related
I have a simple form:
<form class="form-contact-warp form-calc-ship cb-form" action="javascript:redirect();">
<input class="form-control" required="" id="textBox" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<button type="submit" class="btn-main-color btn-block"> Create page</button>
</form>
If I put in input field the text daniel, I want to append a link.
Example:
I put daniel in and I click submit. I want to appear below the link
www.example.com/daniel and the text This is your link.
Thanks
I think the best way to do this is to use jQuery or JavaScript by itself:
<form class="form-contact-warp form-calc-ship cb-form" action="" method="post">
<input class="form-control" required="" id="textBox" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<button type="submit" class="btn-main-color btn-block"> Create page</button>
</form>
<div id="response"></div>
<!-- add jquery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function(){
$('form').on('submit',function(e){
e.preventDefault();
$('#response').html('This is your link:<br />http://www.example.com/'+encodeURI($('#textBox').val()));
});
});
</script>
Here is a jQuery demo found at jsFiddle
Here is the same thing, only it changes when you type.
If you want to use purely PHP, you need to check something has been submitted:
<form class="form-contact-warp form-calc-ship cb-form" action="" method="post">
<input class="form-control" type="text" name="code" size="15" placeholder="USI-TECH affiliate ID">
<input type="submit" class="btn-main-color btn-block" value="Create page" />
</form>
<?php
# Check if there is a post
if(!empty($_POST['code'])) {
# You want to make sure you remove possible html and covert the string to a url.
echo 'This is your link:<br />http://www.example.com/'.urlencode(trim(strip_tags($_POST['code'])));
}
Using HTML form with action = "www.google.com", but it redirect to link including localhost/www.google.com . My example code is for your reference. Please anyone help me.
My Forms as follows :
<form method="POST" action="www.google.com">
<p>
<label for="name">Name:</label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">Email:</label>
<input type="email" name="email" id="email">
</p>
<p>
<label for="comments">Comments:</label>
<textarea name="comments" id="comments"></textarea>
</p>
<p>
<input type="submit" name="send" id="send" value="Send Comments">
</p>
</form>
But, the file when click send button, it redirects to
" http://localhost/basic/www.google.com" error page. Can any one suggest me to resolve the issue.
It is not allowed to send POST request directly to google.com. Why do you want to do this? In the action argument you should have own script which can process request from your form.
Replace your form action
From
action="www.google.com"
To actual link
action="https://www.google.com"
When I submit a form using the attached code, instead of the message appearing in the div, the screen is refreshing itself and it is holding the completed form in the browser cache. I have obviously got it wrong somewhere and would be grateful if someone could point out my error. I have posted the relevant code, but if there is something I have missed, then please let me know.
In firebug, I can see the correct data that is being returned in the post tab.
I wasn't sure of the best place to post, so if this is incorrect, admin, please amend as you see fit. many thanks.
jquery code
//Begin function to submit report form
$(function(){
$(".frmreport").submit(function(){
var formdata = $(this).serialize();
$ajax({
type: "POST",
url: "../frm10010.php",
data: formdata,
dataType: "json",
success: function(msg){
$("#report_result").html("You have succesfully submitted your report. Thank you.");
}
});
return false;
});
});
// End function to submit report form
frm10010.php
<?php
$dept = mysql_real_escape_string($_POST['dept']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$position = mysql_real_escape_string($_POST['position']);
$feedback = mysql_real_escape_string($_POST['feedback']);
$form = array('dept'=>$dept, 'name'=>$name, 'email'=>$email, 'position'=>$position, 'feedback'=>$feedback);
$result = json_encode($form);
echo $result;
?>
html
<div id="report_result"></div>
<div id="formShow">
<form class=frmreport" method="post" class="webform">
<fieldset>
<legend><span class="subtitle">Submit Technical Report</span></legend>
<label for="dept">Department</label>
<input id="dept" name="dept" class="text" type="text" />
<label for="name">Full Name:</label>
<input id="name" name="name" class="text" type="text" />
<label for="email">Email address:</label>
<input id="email" name="email" class="text" type="text" />
<label for="position">Position:</label>
<input id="position" name="Position" class="text" type="text" />
<label for="feedback">Problem:</label>
<textarea name="feedback" cols="22" rows="5"></textarea>
</fieldset>
<input class="submit" type="submit" name="submit" value="Submit Report" />
<input class="cancel" type="reset" name="cancel" value="Clear Report" />
</form>
</div>
You have couple of errors here
$ajax({ should be $.ajax({
Second you have an error in the form class
<form class=frmreport" method="post" class="webform">
should be
<form class="frmreport" method="post" class="webform">
Don't use
$(".frmreport").submit(function(){
Instead use
$("#sub_btn").click(function(){
And in html
<input class="submit" type="submit" name="submit" value="Submit Report" />
Change it to
<input class="submit" id="sub_btn" type="button" name="submit" value="Submit Report" />
Another way to do it making submit handler false. But above solution will work here. There is also . is missing in ajax call.
I need to have a form that when filled out will create a variable and then goto a url with that variable in the url.
Something like this (but that works) :)
<form action="?????" method="?????">
Number: <input type="text" name="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL">
</form>
When the submit is pressed I need it to goto http://somewhere.com?url=VALUEHERE
Any ideas?
Use method="GET" to place the variables in the url:
<form action="http://somewhere.com/" method="GET">
Number: <input type="text" name="url" value="" /><br />
<input type="submit" name="submit" value="Goto URL" />
</form>
Posting this form will go to http://somewhere.com/?url=USER_INPUT_URL
Different from 1st. No form needed, add an attribute named 'id' for the textfield,then defined a javascript function to retrieve the value of textfield,then do the jump, Hope usefully.
<form action="?????" method="?????">
Number: <input id="url1" type="text" name="url1" value=""><br>
<input type="button" name="submit" value="gotoURL()">
</form>
<script>
function gotoURL(){
window.location='http://somewhere.com?url='+document.getElementById('url1').value;
}
</script>
<form>
Number: <input type="text" name="url1" id="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL" onclick="redirect()">
</form>
<script>
function redirect()
{
window.location='http://somewhere.com?url=' + document.getElementByID('url1').value;
}
</script>
I have a form and need to submit it and save the data as a JSON file.
Is it possible?
If so how please?
Here is my simple form below.
<form action="#" method="">
<div data-role="fieldcontain">
<label for="date">Date Input:</label>
<input type="date" name="date" id="date" value="" /><br /><br />
<label for="textarea">Event:</label>
<textarea cols="40" rows="8" name="textarea" id="textarea"></textarea>
<input type="submit" value="save to json" />
</div>
</form>
<?php
$file = dirname(__FILE__).'/form-data-'.time().'-'.rand(1000,9999);
file_put_contents($file, json_encode($_REQUEST));
?>
Read this post on google http://www.ryancoughlin.com/2009/05/04/how-to-use-jquery-to-serialize-ajax-forms/
I found it by googeling "jquery serialize form"
just use json_encode function like this json_encode($_POST)