Web site: www.matka-opas.com/ahaa4.php
If i push SEARCH-1 and then SEARCH-2 it works ok,
but how it could do by one search button ?
<?php
$depairport = $_POST['depairport'];
$ddestination = $_POST['ddestination'];
$ddday = $_POST['ddday'];
$depmonth = $_POST['depmonth'];
$depyear = $_POST['depyear'];
$retday = $_POST['retday'];
$retmonth = $_POST['retmonth'];
$retyear = $_POST['retyear'];
$aikuisia = $_POST['aikuisia'];
$osoite = $depairport . $ddestination . $ddday . $depmonth . $retday . $retmonth;
?>
<form method="post">
<input type="submit" value="SEARCH 1">
thanks ! ;]
If i push SEARCH-1 and then SEARCH-2
it works ok, but how it could do by
one search button ?
Just specify one search button and it will submit the form it is under. And you shouldn't be specifying more than one submit button for a particular form.
Here is what you should have:
<form method="post" action="">
.............
.............
.............
<input type="submit" value="SEARCH">
</form>
if you want to submit your form to http://www.travelstart.fi/combo/ you should put the url in the action attribute of the form. Your form will be posted to that url when it is submitted with <input type="submit" value="SEARCH">
<form method="post" action="http://www.travelstart.fi/combo/">
You also might want to learn more about semantic web and the separation of content and markup. I can understand you want to use tables in this kind of layout but 3 <br> to create a top margin? I saw you included a stylesheet in your page so...
EDIT: Now that your question is updated I think I understand it better. If you don't need any server-side functionality to calculate the url it might be better to put this functionality in javascript. This means it will be executed inside the browser. This saves you a round-trip to the server and so makes your page navigate a lot faster. This is a quick setup to get you started:
<form id="myForm">
...
<input type="submit" />
</form>
<script type="text/javascript">
myForm.onsubmit = function() {
window.location = 'http://www.travelstart.fi/combo/' + myForm.depairport + myForm.ddestination + myForm.ddday + myForm.depmonth + myForm.depyear + myForm.retday + myForm.retmonth + myForm.retyear + myForm.aikuisia;
return false;
}
</script>
As a disclaimer: this is not the best way to program it, it is just a short example to guide you in the right direction. Getting the right javascript code for what you want to achieve is a different question on SO.
It will probably not work right away since I don't think that will result in a valid url but I hope you get the picture. To make it cross-browser compatible you might want to use a javascript library like JQuery.
if you are trying to submit data
<input type="submit" value="SEARCH 1">
and then go to different url
to combine this you can use php that would detect a submit and redirect user to a different page...
as example:
$depairport = $_POST['depairport'];
$ddestination = $_POST['ddestination'];
$ddday = $_POST['ddday'];
$depmonth = $_POST['depmonth'];
$depyear = $_POST['depyear'];
$retday = $_POST['retday'];
$retmonth = $_POST['retmonth'];
$retyear = $_POST['retyear'];
$aikuisia = $_POST['aikuisia'];
$osoite = $depairport . $ddestination . $ddday . $depmonth . $retday . $retmonth;
if (isset($_POST['Submit'])) {
header( 'http://www.travelstart.fi/combo/'.$osoite ) ; }
you might want to change html just to:
<input type="submit" name="Submit" value="SEARCH 1">
thats all - make sure You are using POST method submiting the data
Related
I want to do an equation using the values I get from the input boxes called ampMin, voltMin and hastMin...
I'm not sure if it's a syntax problem or my method of approach is plain wrong.. Here's is an example of how the equation should look and work like with Excel.
What am I doing wrong? Thank you for your time!
EDIT: worth mentioning is that the whole block of code is within "strckenergi.php".
<html>
<title>Sträckenergi</title>
<body>
<h3>Svetsmetod: 111</h3>
<h4><i>Med K=0.8</i></h4>
<pre>
<form method="post" action="strckenergi.php">
Amp. Min <input type="text" name="ampMin"> Volt. Min <input type ="text" name="voltMin"> Hast. Min <input type="text" name="hastMin"> </pre>
<?php
echo "kJ/mm (minimum) = " . $qMin
$qMin = ( $ampMin * $voltMin ) / (( $hastMin * 1000 ) / $hastMin * 0.8));
?>
</body>
</html>
This works.
<html>
<title>Sträckenergi</title>
<body>
<h3>Svetsmetod: 111</h3>
<h4><i>Med K=0.8</i></h4>
<pre>
<form method="post" action="form.php">
Amp. Min <input type="text" name="ampMin"> Volt. Min <input type ="text" name="voltMin"> Hast. Min <input type="text" name="hastMin">
<input type="submit" value="submit"> </pre>
</form>
<?php
if($_POST){
$voltMin = $_POST['voltMin'];
$ampMin = $_POST['ampMin'];
$hastMin = $_POST['hastMin'];
$qMin = ( $ampMin * $voltMin ) / ( $hastMin * 1000 ) / $hastMin * 0.8;
echo "kJ/mm (minimum) = " . $qMin;
}
?>
You don't appear to be using forms correctly. If you want the browser do be able to display it right away, you should use JavaScript instead. PHP will require an additional pageload, or an AJAX request.
And in order to post the form, you need a submit button. Otherwise, the browser won't know what to do with it.
Further, your first PHP line needs a semi-colon, and your second one needs to be above the first - otherwise, the interpreter won't know what your value is when printing it, because it hasn't been calculated yet.
To be honest, I think you need to start by googling for how to construct an HTML form, then you can look up simple JavaScripts. Lycka till!
First off, as Joel Hinz says above, you need a submit button so the page knows when the user is done inputting and wants to send the form to the server for processing.
Second, you need to close the form with a tag.
Third, you're probably better off sticking with php at this stage; JavaScript can be a bit tricky and mighty frustrating for beginners.
This is a rough approximation of how your form should look.
<form method="post" action="strckenergi.php">
Amp. Min <input type="text" name="ampMin">
Volt. Min <input type ="text" name="voltMin">
Hast. Min <input type="text" name="hastMin">
<input type="submit" value="submit">
</form>
See http://www.tizag.com/phpT/forms.php for a clear explanation of forms.
OK first thing first. When the form is submitted, the values contained in the $_POST array aren't immediately available to the script on the server which processes the input.
For that you will need something like the following:
<?php
if($_POST){// this checks for the existence of the $_POST array, i.e. was something submitted
//now we're assuming a form was submitted
$voltMin = $_POST['voltMin'];
$ampMin = $_POST['ampMin'];
$hastMin = $_POST['hastMin'];
$qMin = ( ($ampMin*$voltMin)/($hastMin*1000)/($hastMin*0.8) );
echo "kJ/mm (minimum) = " . $qMin;
}// if($_POST)...
?>
Then you can process the elements, and print out the results of your calculations.
Oh, and drop the pre tags unless you really need them.
Hi guys I have html form which is set to action = something.php. now i want to autosubmit this form 9 times when submit button on the form is clicked. can i do this using PHP. Thanks in advance.
Since PHP is a server side script, you cannot actually submit the form 9 times. You can, however, do whatever you're doing with the data on the server side 9 times in a for loop.
for($i = 0; $i < 9; $i++) {
// use $_POST here and do your stuff
}
do you want to submit the form 9 times to the same PHP script, or do you just want to handle the submission 9 times? Don't think you can do the former from PHP, but the later would be easily handled via a loop:
for ( $counter = 0; $counter < 9; $counter += 1) {
\\ do your stuff
}
Do you have a particular reason why you want to submit the form vs. just running through the logic multiple times?
No, you can't do this in PHP. At least not the way you are thinking of doing it (actual multiple POST actions from your form page). The action of posting will automatically take the user to the page you are posting to, not giving you an opportunity to POST again. You could of course POST to another script form the script you POSTed to, but I don;t think this is what you are asking.
To make actual repeated physical POSTs you would likely need to use AJAX methods.
HTML Page
<form id="form1" name="form1" method="post" action="form.php">
<input type="text" name="name" id="name" />
<input type="text" name="email" id="email" />
<input type="submit" name="button" id="button" value="Submit" />
</form>
PHP Page
<?php
for($i=1; $i<=9; $i++) {
// Your posting stuff
echo $_POST['name'];
echo '<br>';
echo $_POST['email'];
echo '<br>';
}
?>
This is the way you can use.
I'm attempting to create a link for users to click that will remove them from a list. I'm trying to figure out how to do this without using a submit button and without using $_GET(if possible).
Anyway, I'm afraid to do it with $_GET (the way I have it now), because the user can type this in the URL (even though 99% wouldn't know how or think to do this) and they would be removed from the list.
How can I name the link so I can use $_POST?
$attendingUsers = mysql_query("Select acceptedInvites from events where eventID = ".mysql_real_escape_string($_GET['eventID'])." ");
$users= mysql_fetch_array($attendingUsers);
$user = $users['acceptedInvites'];
if(preg_match("/$userid/", $user)){
echo "You are attending this event</br>";
echo 'Click here to remove yourself from the list';
if($_GET['delete']=1){
$sql=...
}
}
Is it possible to do this without using $_GET? Thanks!
Never delete via a link. Read The Spider of Doom
Best way is to link to a "delete" page with an "are you sure" form. Submitting the form (via POST) performs the delete and redirects back to a suitable results page.
For example
Click here
to remove yourself from the list
Then, in remove.php
<?php
// get Event details via $_GET['eventID']
if (isset($_POST['confirm'])) {
// delete via SQL
// redirect
header('Location: http://example.com/events.php');
exit;
}
// display event details
?>
<form method="post" action="remove.php?eventID=<?php echo $eventId ?>">
<p>Are you sure?</p>
<input type="submit" name="confirm" value="Remove me from this event">
</form>
You should probably also look into CSRF protection but that's really outside the scope of this question.
Your are required to use either $_GET or $_POST
<form action="delete.php" method="post">
<input type="hidden" name="eventId" value="yourEventId" />
<a href="#" onclick="this.form.submit();" > Delete</a>
</form>
If I have my JavaScript right, this should do the trick:
Delete
<form id="delete" action="delete.php" method="post">
...
</form>
The link will then submit the form.
You could use some kind of encoding to make the get var unreadable, like an md5 or even an encrypted string.
<select name="gamelist" id="gamelist">
<option value="1">Backgammon</option>
<option value="2">Chess</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit" />
i want to grab the selected value and place in in a var
any idea?
thanks
Depends on your form tag.
<form method="post">
Will pass the value to $_POST['gamelist']
While
<form method="get">
Will pass the value to $_GET['gamelist']
Ofcourse, only after hitting the submit button. As morgar stated, this is pretty basic form procession. I doubt you've used google or followed a tutorial, this is almost one of the first things one learn when working with forms and PHP. We arent here to give you full solutions, take this as an example and create the full page yourself:
if($_SERVER['REQUEST_METHOD'] == "Y") {
$choice = $_Y['gamelist'];
// other stuff you want to do with the gamelist value
} else {
echo '<form method="Y" action="file.php">';
// the rest of your form
echo '</form>';
}
Replace Y with either GET or POST.
$choice = $_REQUEST['gamelist']; //works with get or post
$choice = $_POST['gamelist']
if it is a POST, or $_GET if not.
Does anyone know how I can get the value of an input box, without having a form? I want a submit button, but instead of submitting a form, I want it to change data in a MySQL database. Something like this maybe?
$img1="WHAT DO I PUT HERE?"
$idx=1
$sql="INSERT INTO games SET img1='$img1' WHERE id=$idx";
$result=mysql_query($sql);
Could I use that code on a "onclick" event? The input box's name and id is "img1".
If you don't want to submit a form, the only two other ways of accomplishing this are to click a link with the data as query parameters in the url, or use AJAX to send the data to the server in the background.
update:
Javascript, as usual. You'd put a link or button somewhere on the page with "Send to Server" or whatever for the text. The script would pull your information from the input fields, and then send it on to the server via an AJAX call. Something along these lines (note that I'm using Mootools for all this, as it makes life much easier than having to do the remote calls yourself):
function clickHandler() {
var img1 = $$("input[name='img1']")[0].value;
var r = new Request.JSON({
'url: 'http://yourserver.example.com/script.php',
'method': 'post',
'onComplete': function(success) { alert('AJAX call status: ' + (success ? 'succeeded': 'failed!'); },
'onFailure': function() { alert('Could not contact server'); },
'data': 'img1=' + img1
}).send();
}
and on the server you'd have something like:
<?php
$img1 = mysql_real_escape_string($_POST['img1']);
$idx=1;
$sql="INSERT INTO games SET img1='$img1' WHERE id=$idx";
$result=mysql_query($sql);
echo (($result !== FALSE) ? 1 : 0);
You'd probably want something more complicated than this, but this is the basis of an AJAX application. Some client-side javascript that makes requests, and a script on the server that handles them and returns any data/errors as needed.
Don't know if your completely against using a form or just might not know how to keep it hidden.
You can create a hidden form that submits the info with the click of a button.
<form name="hidden-form" action="youraction.php" method="post">
<input type="hidden" name="submitme" value="I get submitted">
<input type="hidden" name="submitmetoo" value="I get submitted">
<input type="hidden" name="submitmeaswell" value="I get submitted">
<input type="hidden" name="dontleavemeout" value="I get submitted">
<input name="submit" type="submit" value="SUBMIT" />
</form>
However anyone that looks at your html will be able to see this
I guess this is what you looking for.
this will only work if your html and php are on the same file...
<html>
<head>
</head>
<body>
<input type='text' id='user' placeholder='user'>
</body>
</html>
<?php
$val = "
<script>
document.write(document.querySelector('#user').value);
</script>
";
echo $val;
?>