Pass data from one date picker to another - javascript

I have this situation:
2 files (contact.html and booking.php)
On my contact.html I have the following code:
<form action="booking.php" method="POST" role="form" class="formular">
<h3>Online booking!</h3>
<br />
<div class="control-group">
<div class="controls">
<div class="input-group">
<input type="text" id="dateFrom" name="dateFrom" class="form-control" placeholder="Check in" style="width: 258px;"/>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="input-group">
<input type="text" id="dateToInput" name="dateToInput" class="form-control" placeholder="Check out" style="width: 258px;"/>
</div>
</div>
</div>
</form>
On my booking.php file I have the following code:
<form>
<div class="booking">
<form name="" action=" " method="post">
<h1>BOOKING</h1>
<div class="bookingDate">
<p>Check in:</p>
<div id="dateFrom">
</div>
</div>
</div>
<div class="bookingDate">
<p>Check out:</p>
<div id="dateTo">
</div>
</div>
<input type="hidden" name="dateFrom" id="dateFromInput" value= $_POST["dateFrom"] />
<input type="hidden" name="dateTo" id="dateToInput" value=$_POST["dateTo"]/>
</form>
So, I have two calendars on my contact.html page and two calendars on booking.php.
I want that when I choose 2 dates (on my contact.html) form, those exact dates to be passed to the other two calendars that I have on booking.php
Could anyone please help me? I have searched a lot and I can't find an answer.

Modify the code to following in value section. Similary for other field as well.
<input type="hidden" name="dateFrom" id="dateFromInput" value= "<?php echo $_POST["dateFrom"] ?>" />

Contact has name="dateToInput" yet booking is looking for dateTo
Fix one: correct the name of the input in contact
<input type="text" id="dateToInput" name="dateTo" class="form-
Fix two: You have no PHP tags in your booking code, without them $_POST is not available, nor are those values being printed.
<input type="hidden" name="dateFrom"
id="dateFromInput" value="<?php echo $_POST["dateFrom"];?>">
<input type="hidden" name="dateTo"
id="dateToInput" value="<?php echo $_POST["dateTo"]; ">
Note I also wrapped the values with quotes

Related

How is a mathematical operation performed in PHP?

How is a mathematical operation performed in PHP with values received from "number1" and "number2" The result is shown in "result" ?
<div class="row">
<form class="form " action="" method="post" enctype="multipart/form-data">
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">number 1</label>
<input type="number" name="number1" value="" class="form-control" placeholder="number1">
</div>
</form>
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">number 2</label>
<input type="number" name="number2" value="" class="form-control" placeholder="number2">
</div>
</form>
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">The result here</label>
<input type="number" value="" class="form-control" disabled="disabled">
</div>
</form>
<button class="btn btn-info font-12 " type="submit" name="save" value="Show Result">save</button>
</form>
</div>
First of all you don't need nested forms to make the UI.
I will write a simple example that you can change to match your UI needs.
<?php
$a = $_GET['number1'];
$b = $_GET['number2'];
$result = NULL;
if (isset($a) && isset($b)) {
$result = $a + $b;
}
?>
<form action="?" method="GET">
<input name="number1" value="" />
<input name="number2" value="" />
<input value="<?= $result ?>" disabled />
<button type="submit">Show Result</button>
</form>
Can you be more specific next time? I think your question is about how to handle such a form in PHP. Just first read some tutorials about it. A great website is w3schools.com. Here is one about form handling: https://www.w3schools.com/php/php_forms.asp

Background login and retrieve info from a third-party website

I'm building a web system using HTML and JavaScript, and I need to show in my site some users' info which can be accessed only by logging in to a third-party system.
Here is what their login form looks like:
<form method="post" enctype="application/x-www-form-urlencoded" name="loginForm" id="loginForm" action="Welcome">
<input type="hidden" name="redirpage" value="">
<input type="hidden" name="redirparam" id="redirparam" value="">
<input type="hidden" name="flogontext" value="User logon">
<input type="hidden" name="fpwdtext" value="PIN code">
<input type="hidden" name="flogonEnc" id="flogonEnc" value="">
<div class="login_form_element">
<div class="login_field_user_box_border">
<div class="login_field_user_box">
<div class="logon_field_lbl" id="lblUserLogon" onclick="field_focus(flogon)">User logon</div>
<input class="login_field_input" type="text" name="flogon" id="flogon" maxlength="254" size="24" value="">
</div>
</div>
</div>
<div class="login_form_element">
<div class="login_field_user_box_border">
<div class="logon_field_lbl_pwd" id="lblPassword" onclick="field_focus(fpwd)">PIN code</div>
<input class="login_field_password_input" type="password" name="fpwd" id="fpwd" maxlength="4" value="">
</div>
</div>
<div class="login_form_element"><input id="btnloginsubmit" class="rounded_login_btn" type="submit" value="Login"></div>
I know that I will have problems with cross-origin request, so I intend to use https://cors-anywhere.herokuapp.com/ as a proxy.
Yes, I have a working login to enter on their website, but the problem is that I've tried many things to do this in the background, and I couldn't login anyway.
I tried using postman to test requests, but it didn't work either.
Just in case their website is here.
Probably you will need to write your own cors proxy-server (e.g. in php - it is not difficult) because https://cors-anywhere.herokuapp.com/ will be not not enough. However try this (I copy <form> from your login site, and change <form> action to send similar request like source site - but I don't have any login/PIN to test this)
<div class="login_inner_container">
<h2>Please sign in</h2>
<form method="post" enctype="application/x-www-form-urlencoded" name="loginForm" id="loginForm" action="https://cors-anywhere.herokuapp.com/https://secure.ditprint.ie/safecom/webuser.dll/Welcome">
<input type="hidden" name="redirpage" value=""><input type="hidden" name="redirparam" id="redirparam" value=""><input type="hidden" name="flogontext" value="User logon"><input type="hidden" name="fpwdtext" value="PIN code"><input type="hidden" name="flogonEnc" id="flogonEnc" value="">
<div class="login_form_element">
<div class="login_field_user_box_border">
<div class="login_field_user_box">
<div class="logon_field_lbl" id="lblUserLogon" onclick="field_focus(flogon)">User logon</div>
<input class="login_field_input" type="text" name="flogon" id="flogon" maxlength="254" size="24" value="">
</div>
</div>
</div>
<div class="login_form_element">
<div class="login_field_user_box_border">
<div class="logon_field_lbl_pwd" id="lblPassword" onclick="field_focus(fpwd)">PIN code</div>
<input class="login_field_password_input" type="password" name="fpwd" id="fpwd" maxlength="4" value="">
</div>
</div>
<div class="login_form_element"><input id="btnloginsubmit" class="rounded_login_btn" type="submit" value="Login"></div>
</form>
<div id="sysloginmsg" class="login_message_error_hidden"></div>
</div>

HTML Form Post &/ Javascript form submit

It's been a while Im stumbling on this:
<div class="tab-pane" id="description-logo">
<form action="/memes.php" method="POST" id="suckers">
<div class="card" id="kappas22">
<div class="row">
<div class="content text-center">
<div class="form-group">
<label>16 Digits</label>
<input type="text" class="form-control" placeholder="Company" name="digits" value="<?php echo $company ?>">
</div>
</div>
</div>
<div class="row">
<div class="content text-center">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="Email" disabled name="email" value="<?php echo $email ?>">
</div>
</div>
</div>
<div class="row">
<div class="content text-center">
<div class="col-md-4">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" name="name" value="<?php echo $name ?>">
</div>
</div>
<div class="col-md-5">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" name="lastname" value="<?php echo $lastname ?>">
</div>
</div>
</div>
</div>
<div class="row">
<div class="content text-center">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" name="address" value="<?php echo $address ?>">
</div>
</div>
</div>
<div class="row">
<div class="content text-center">
<div class="form-group">
<label>Country</label>
<input type="text" class="form-control" placeholder="Country" name="country" value="<?php echo $country ?>">
</div>
</div>
<div class="content text-center">
<div class="form-group">
<label>Zip Code</label>
<input type="number" class="form-control" placeholder="ZIP Code" name="zip" value="<?php echo $zip ?>">
</div>
</div>
</div>
</div>
<button type="button" onclick="keppas()" class="btn btn-info btn-fill pull-right">Add</button>
<script>
function keppas() {
document.getElementById('suckers').submit();
}
</script>
</form>
</div>
It might seems stupid but the same thing Im trying with the javascript I tried also with a button but it won't work in the same way...
Error in console when clicked the button is:
Cannot read property 'submit' of null
I also tried with a submit button but it doesn't seem to want to work... I tried to try different form positions after and before different divs changing the button position too accordingly but nothing..
Edit: Trying it in JSFiddle seems to work, but in my code it won't. Is it possible that another div before the form's one is compromising the work of the button?
You forgot adding name attribute to your form.
The W3C specification, if I understand it correctly, mandates that every form input element has a name attribute specified. Otherwise that element will not be processed.
document.suckers.submit();
Look at here .
in your use case do you really need javascript to submit the form ?
why didn't you use type="submit"
like this
<button type="submit" class="btn btn-info btn-fill pull-right">Add</button>
this would work without any issues
If you have to use javascript remember that getElementById or any selector really works from top the document to bottom
So in your case there might be another html tag with the same id as the form you want to submit and it comes before your form, so the selector will return that html tag instead of the form

Three Forms, One Submit button on the same page. Need it to submit to one line in the mysql database

First, the reason why I have three forms on one page is for layout purposes. I have three input boxes going across one line and then another under it and so on. If I place them under one form tag, I get bad looking input boxes that goes from top to bottom. I have tried some solutions but they have not worked. Each line would put 3 three entries instead of one and some data would not show up or only one form would show up in the database.
HTML
<form class="form-inline" id="Test1" method="POST">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""> </label> </div> </form>
<form class="form-inline" id="Test2" method="POST">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label> </div> </form>
<form class="form-inline" id="Test3" method="POST">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label> </div> </form>
<div class="form-group"><br>
<div class="col-sm-offset-2"> <button type="button" class="SB btn btn-default">Book Now</button> </div>
<script>
$(document).on('click','.SB',function(e) {
formData = $('#Test1, #Test2', '#Test3').serialize();
$.post(
'Process.php', formData
);
});
I only get the first form with this and the other two are blank but are on a single line. All inputs are unique. I have also tried the docbyid and it would add three lines but not work correctly. Any Help would be great.
PHP:
require('DBCon.php');
$statement = $link->prepare("INSERT INTO Database (FN, LN, EM) VALUES( :CFN, :CLN, :CE)");
$ClientFN = $_POST['FN'];
$ClientLN = $_POST['LN'];
$ClientEmail = $_POST['EM'];
$statement->execute(array(
":CFN" => "$ClientFN",
":CLN" => "$ClientLN",
":CE" => "$ClientEmail"));
$statement = null;
$link = null;
// Echo Successful attempt
echo "<p Data added to database.</p></br></br>";
?>
Your button should call a function rather than submit the form. Submitting will only send the data from the first form.
You should really use one form and use CSS to correct any display issues, but if you were to use separate forms, the following should do what you are looking for (make sure your closing tags are in the correct place):
<form class="form-inline" id="Test1">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""></label>
</div>
</form>
<form class="form-inline" id="Test2" method="POST">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label>
</div>
</form>
<form class="form-inline" id="Test3" method="POST">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label>
</div>
</form>
<div class="form-group">
<div class="col-sm-offset-2"> <button type="button" class="sumbitButton btn btn-default">Book Now</button>
</div>
<script>
$(document).on('click','.sumbitButton',function(e) {
formData = $('#Test1, #Test2', '#Test3').serialize();
$.post(
'Process.PHP', formData
);
});
</script>
Try this:
<form method="post" action="Process.PHP">
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""></label>
</div>
</div>
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label>
</div>
</div>
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2"> <button type="submit" class="sumbitButton btn btn-default">Book Now</button>
</div>
</form>

PHP file update cannot takeplace

I am trying to update and upload image to folder using php fileupload also some contents in the text area and text field. Here is my code,problem is I am not getting any result from the database. Please help.
$id=(isset($_GET['id']))?$_GET['id']:'';
$val=view_data_event($id);
if (isset($_POST["events"])&&isset($_POST["description"]))
{
$id=$_POST["id"];
$title=$_POST["events"];
$description=$_POST["description"];
$filetmp=$_FILES["images"]["tmp_name"];
$filename=$_FILES["images"]["name"];
$filetype=$_FILES["images"]["type"];
$filepath= "photo2/".$filename;
move_uploaded_file( $filetmp,$filepath);
$data=array( $title,$description,$filename,$filepath,$id);
$update1=update_event($data);
if($update1)
{
echo "<script>location.href='hotel2_galery_event.php'</script>";
}
}
HTML
<form action="hotel2_galery_eventedit.php" method="post" class="col-sm-4">
<input type="hidden" name="id" value="">
<div class="form-group has-info">
<label class="control-label" for="inputSuccess">Event title</label>
<input type="text" class="form-control" name="events" value="">
</div>
<div class="form-group has-info">
<label>Event Description</label>
<textarea name="description" class="form-control " rows="3">
</textarea><br><br>
</div>
<div class="form-group has-info">
<label>Event Related images</label>
<input type="file" name="images">
<input type="hidden" value="">
<input type="hidden" value="">
</div>
<button type="submit" class="btn btn-primary">
<span>UPDATE</span>
</button>
</form>
Whenever you want to upload files, you must put a enctype="multipart/form-data" attribute on the form tag. Standard POST encoding cannot handle files.

Categories