I am having trouble to post a html form. I am posting one form and getting the post value to my variable and then I am post this form but this form is not posting.
HTML code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" autocomplete="off">
<div class="widget-box">
<div class="widget-title"> <span class="icon"> <i class="icon-user"></i> </span>
<h5>Amc details</h5>
</div>
<div class="widget-content">
<div class="controls controls-row">
<div class="control-group span3">
<label for="normal" class="control-label">Installation Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-ins-date" data-date="01-02-2016" name="amc-ins-date" data-date-format="dd-mm-yyyy" class="datepicker span12" placeholder="Enter installation date">
</div>
</div>
<div class="control-group span3">
<label for="normal" class="control-label">Start Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-start-date" data-date="01-02-2016" name="amc-start-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc start date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">End Date<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-end-date" data-date="01-02-2016" name="amc-end-date" data-date-format="dd-mm-yyyy" placeholder="Enter amc end date" class="datepicker span12 ins-date">
</div>
</div>
<div class="control-group span3">
<label class="control-label">Amount<span style="color:red">*</span></label>
<div class="controls">
<input type="text" id="amc-amount" name="amc-amount" class="span12" placeholder="Enter amc amount">
</div>
</div>
</div>
</div>
<div class="form-actions">
<input style="float:right" type="submit" name="amc-installation" class="btn btn-success" value="Save">
</div>
</form>
PHP code:
// i have submitted a form here and its posted
// installation details
$mc_serial = $_POST['mc-serial'];
$mc_model = $_POST['mc-model'];
$contract_type = $_POST['contract_type'];
$no_of_copies = $_POST['no-of-copies'];
$spare_part = join(",",$_POST['spare-part']);
$eng_name = $_POST['eng-name'];
$review = $_POST['review'];
// check if the machine already exits
if(IsMachine($mc_serial,$con)){
echo msgIsMachine();
exit();
}
if($contract_type == 'AMC'){
require './forms/amc.php'; // this is the html i have shown above
} elseif ($contract_type == 'ASC') {
require './forms/asc.php';
} elseif ($contract_type == '4C') {
require './forms/4c.php';
} elseif ($contract_type == 'RENTAL') {
require './forms/rental.php';
} elseif ($contract_type == 'WARRANTY') {
require './forms/warranty.php';
}
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);($_POST);
}
The output of var_dump is NULL. I don't get any problem.
You echo the second form (during the script which responds to the submission of the first one), but then immediately check for values returned from it within the same script execution. You have to wait for the user to post the form back before you can check the submitted values. This would be a separate postback, and therefore a separate execution context for the PHP.
So the code to check the values from the second form needs to be in a separate section (or file) which is triggered by the submission of the second form.
There's no $POST in PHP you should use $_POST instead :
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
NOTE : You should place the var_dump($_POST); inside the if statement, so it will be trrigered just after the submit.
Hope this helps.
if(isset($_POST['amc-installation']) && !empty($_POST['amc-installation'])){
echo "posted";
var_dump($_POST);
}
You should use $_POST not $POST.
Hope this will helps you :)
Related
So, I have multiple forms on a page and I am trying to submit them conditionally using the same button, for some reason, I cannot trigger the submit button. Below is my code.
$("#save_contact").on("click", function () {
var contact_type = $("#contact_type").val();
console.log(contact_type);
if (contact_type == 2) {
console.log("here");
$('#supplier_form').submit();
} else if (contact_type == 3) {
} else if (contact_type == 4) {
} else if (contact_type == 5) {
} else if (contact_type == 1) {
}
});
This is my form, at the moment I have only created 1 form.
<div id="supplier_div" class="form_to_save">
<form id="supplier_form" name="supplier_form" action="{{route('save_reception_contacts')}}">
<hr>
<h4>Supplier</h4>
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Company</label>
<input type="text" name="company" id="company" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Notes</label>
<textarea name="notes" id="notes"></textarea>
</div>
</div>
</div>
<input type="hidden" name="contact_type_hidden">
<input type="hidden" name="user_type_hidden">
</form>
</div>
<div class="col-md-6">
<button type="button">Back</button>
<button type="button" class="save" id="save_contact">Save</button>
</div>
You have unclosed <hr> at
<form id="supplier_form" name="supplier_form" action="{{route('save_reception_contacts')}}">
<hr>
and an unclosed <div class="row">
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="row">
otherwise I can't see anything wrong with submitting the form, you haven't provided relevant HTML that i could create the snippet.
You are creating a new variable and assigning the value of "contact_type" element. But I can not find this element in the HTML.
I have modified your code:
<div id="supplier_div" class="form_to_save">
<form id="supplier_form" name="supplier_form" action="{{route('save_reception_contacts')}}">
<hr></hr>
<h4>Supplier</h4>
<input type="hidden" name="_token" value="{{csrf_token()}}">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label>Company</label>
<input type="text" name="company" id="company" />
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label>contact_type</label>
<input type="text" name="contact_type" id="contact_type" />
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Notes</label>
<textarea name="notes" id="notes"></textarea>
</div>
</div>
</div>
</div>
<input type="hidden" name="contact_type_hidden">
<input type="hidden" name="user_type_hidden">
</form>
</div>
<div class="col-md-6">
<button type="button">Back</button>
<button type="button" class="save" id="save_contact">Save</button>
</div>
Note that there is now a new input "contact_type".
And here is the script, where you will need to uncomment in order to send the form.
$("#save_contact").on("click", function() {
var contact_type = $("#contact_type").val();
if (contact_type == 2) {
console.log("2");
//$('#supplier_form').submit();
} else if (contact_type == 3) {
console.log("3");
//$('#supplier_form').submit();
} else if (contact_type == 4) {
console.log("4");
//$('#supplier_form').submit();
} else if (contact_type == 5) {
console.log("5");
//$('#supplier_form').submit();
} else if (contact_type == 1) {
console.log("1");
//$('#supplier_form').submit();
}
});
I am assuming you want to send the same and only form, not differents one, as it seems to understand from the initial question.
I have a form in HTML with some checkboxes and I want to send an email with the selected checkboxes in the body, the problem is that the "text" fields are passing to the PHP variables, but the checkboxes values are always set to uncheck when I test it on the PHP file:
HTML:
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control c-check" >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina
</label>
</div>
PHP:
$reservas_bicicletas = '';
if (isset($_POST['checkbox1citadina'])) {
$reservas_bicicletas .= "Citadina: checked\n";
} else {
$reservas_bicicletas .= "Citadina: unchecked\n";
}
echo $reservas_bicicletas;
$reservas_bicicletas always retrieves the else value.
Need help guys, thanks in advance.
remove c-check
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
Basically i have this (i shorted out the form because there are too many elements):
HTML:
<form name="quick_booking" id="quick_booking" method="post" action="assets/reserva-bicicletas.php">
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
<button type="submit" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square">Reservar</button>
</form>
I'm doing a e-commerce admin panel and I need a quick script for inserting data into MySQL. Here's what i've done and it does nothing.
<form action="#" id="form_sample_1" class="form-horizontal" method="post">
<div class="control-group">
<label class="control-label">Package Name<span class="required">*</span></label>
<div class="controls">
<input type="text" name="pkg_name" data-required="1" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Price <span class="required">*</span><small>(In Dollars)</small></label>
<div class="controls">
<input name="pkg_price" type="number" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Package Contains</label>
<div class="controls">
<input name="pkg_contains" type="text" class="span6 " value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">Your Password</label>
<div class="controls">
<input name="sifre" type="password" class="span6 " value=""/>
</div>
</div>
<div class="form-actions">
<button type="button"name="btn" class="btn btn-primary">Send request to server.</button>
</div>
</form>
<!-- END FORM-->
</div> <!--widget box light-grey end-->
<!-- Mass PHP starts here! -->
<?php
echo mysql_error();
include("include/baglan.php");
// set posts here.
$_POST['pkg_name'] = $pkg_name;
$_POST['pkg_price'] = $pkg_price;
$_POST['pkg_contains'] = $pkg_contains;
$sifre = mysql_real_escape_string(md5($_POST['sifre']));
if($_POST['btn'] and $_POST["sifre"] = $sifre){
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES $pkg_name $pkg_price $pkg_contains");
echo "Success.";
}
else {
echo mysql_error();}
It returns nothing! I've re-written all code but nothing! please help me. The databae variables are;
id, auto incerment
pkg_name text
pkg_price int
pkg_contains mediumtext
Assign variable name should be the left side.
// set posts here.
$pkg_name=$_POST['pkg_name'];
$pkg_price=$_POST['pkg_price'];
$pkg_contains=$_POST['pkg_contains'];
Values() is function, put all vars in bracket and split them with ','.
mysql_query("INSERT INTO packages (pkg_name, pkg_price,pkg_contains) VALUES($pkg_name,$pkg_price,$pkg_contains)");
I created a contact form that is placed in the footer. my problem is when the form is submitted, it redirects me to the search results and it says
"No Results Found
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post." I would like to know how can I make this work. THanks!
NOTE: I didn't use any plugin.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// echo $_POST['email'];
echo "FORM SUBMITTED";
$msg=$_POST['msg'];
$email=$_POST['email'];
$name=$_POST['name'];
$subj=$_POST['action'];
$message=$name.' ('.$email.') :'.$msg;
wp_mail( 'psinc123#designsbyps.com', $subj , $message );
}
?>
<form method="POST" action="#" id="contactForm">
<div class="custom-contact-form">
<div class="first-part"><strong class="hey">Hey PS and Company,</strong><br>
<br>
I am <span id="name" contenteditable="true" class="contenteditable details">enter your name</span> and I would like<br>
<input type="hidden" id="name-field" name="name">
to <span id="action" class="contenteditable details chat-topic" style="cursor: pointer;">chat about a project</span>.
<input type="hidden" id="action-field" name="action">
<div id="submit" class="submit submit-first-part">
<div class="text">Next</div>
</div>
</div>
<div class="second-part">
<span id="question" contenteditable="true" data-content="Enter your message" class="contenteditable details">Enter your message</span><br>
<input type="hidden" id="msg-field" name="msg">
<br>My email address is<br><span id="email" contenteditable="true" data-content="you#email.com" class="contenteditable details">you#email.com</span>
<input type="hidden" id="email-field" name="email">
<div id="send" class="submit submit-second-part">
<div class="text">Send</div>
</div>
<div id="cancel" class="cancel">Cancel</div>
</div>
<div class="last-part">
<div id="message"></div><br><br>
<div id="return" class="cancel">Return</div>
</div>
<div class="overlay open">
<div class="choices-wrapper">
<div class="choices">
<div class="line active">know more about us</div>
<div class="line">chat about a project</div>
<div class="line">ask about a job</div>
<div class="line">say YO!</div>
</div>
</div>
</div>
</div>
</form>
You need this type structure :
function process-form () {
#
# -- form processing actions
#
return (0);
}
?> // end function process_form
.
.
.
name is a reserved term in WordPress. Use another key instead.
After submit in signup page my signUp page redirects to info.php where I want to collect additional info of user using email id he gives on signup page but when I tried to get the email id of user through sessions, session return empty value.
THIS IS MY SIGNUP CODE
<?php
session_start();
if(isset($_POST['submit'])){
$name= $_POST['_user'];
$email = $_POST['_email'];
$pass = $_POST['_password'];
//Insert Data
$sql = "INSERT INTO signup(name,email,password)
VALUES('$name','$email','$pass')";
//Data Validation
if(mysqli_query($conn,$sql)){
echo "<script>alert('SignUp Successfull')</script>";
$_SESSION['user_email'] = $email;
header('Location: info.php');
}
else{
echo "<script>window.alert('You are already a user.')</script>";
}
}
mysqli_close($conn);
?>
AND THIS MY INFO.PHP CODE
<?php
session_start();
if(isset($_POST['_submit'])){
if(empty($_POST['_address']) || empty($_POST['_country']) || empty($_POST['_number']) || empty($_POST['_cnic']) || empty($_POST['_passport'])){
echo "<script>window.alert('All fields are required')</script>";
}
else{
$address = $_POST['_address'];
$country = $_POST['_country'];
$number = $_POST['_number'];
$cnic = $_POST['_cnic'];
$passport = $_POST['_passport'];
$email=$_SESSION['user_email'];
$query = "INSERT INTO info(email,address,country,mobile,cnic,passport)
VALUES('$email','$address','$country','$number','$cnic','$passport')";
if(mysqli_query($conn,$query)){
header('Location: ../index.php');
}
else{
echo "<script>window.alert('Error While Entering the data!.')</script>";
}
}
}
mysqli_close($conn);
?>
In addition I use this global session variable for login page and it works fine.
UPDATE
SIGNUP HTML CODE
<div class="outside">
<form class="form-horizontal" role="form" method="post">
<div class="form-group">
<label class="control-label col-sm-3 glyphicon glyphicon-user" for="name"></label>
<div class="control-label col-sm-8">
<input type="text" name="_user" class="form-control" id="name" placeholder="Full Name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">
<img class="glyphicon1" src="../assests/at-sign.png">
</label>
<div class="control-label col-sm-8">
<input type="email" name="_email" class="form-control" id="email" placeholder="Enter Email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3 glyphicon glyphicon-lock" for="password"></label>
<div class="control-label col-sm-8">
<input type="password" name="_password" class="form-control" id="password" placeholder="Enter Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button name="submit" id="submit" value="Upload" type="submit" class="btn btn-default">Confirm SignUp</button>
</div>
</div>
<p>Already a User? LogIn</p>
</form>
</div>
Use this for Returns the auto generated id used in the last query
mysqli_insert_id($link)