Unable / disable select field on checkbox field with several forms - Jquery - php

I have several form having the same fields: A checkbox (bootstrap switch) and a select
I want that when I pick the checkbox, the select switch to enable / disable
Thing is when I do it, only the first form is working :(
Here is my HTML
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam7" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam7" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize"><option value="0">2</option><option value="1">3</option><option value="2" selected="selected">4</option><option value="3">5</option><option value="4">6</option><option value="5">7</option><option value="6">8</option><option value="7">9</option><option value="8">10</option><option value="9">11</option><option value="10">12</option><option value="11">13</option><option value="12">14</option><option value="13">15</option></select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save7"><i></i>Guardar
</button>
</div>
</form>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam8" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam8" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize"><option value="0">2</option><option value="1">3</option><option value="2" selected="selected">4</option><option value="3">5</option><option value="4">6</option><option value="5">7</option><option value="6">8</option><option value="7">9</option><option value="8">10</option><option value="9">11</option><option value="10">12</option><option value="11">13</option><option value="12">14</option><option value="13">15</option></select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save8"><i></i>Guardar
</button>
</div>
</form>
Here is my Jquery
$('input[name="isTeam"]').on('switchChange.bootstrapSwitch', function (event, state) {
var isChecked = $(this).is(':checked');
$('.teamSize').prop('disabled', !isChecked);
});
How can I do so that it work for all the forms in my page???

Check this snippet.
$(function() {
$('input[name="isTeam"]').on('switchChange.bootstrapSwitch', function(event, state) {
var isChecked = $(this).is(':checked');
$(this).closest('form').find('[name="teamSize"]').prop('disabled', !isChecked);
});
$("input[type=\"checkbox\"], input[type=\"radio\"]").not("[data-switch-no-init]").bootstrapSwitch();
});
<link href="http://www.bootstrap-switch.org/dist/css/bootstrap3/bootstrap-switch.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.bootstrap-switch.org/dist/js/bootstrap-switch.js"></script>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam7" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam7" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize">
<option value="0">2</option>
<option value="1">3</option>
<option value="2" selected="selected">4</option>
<option value="3">5</option>
<option value="4">6</option>
<option value="5">7</option>
<option value="6">8</option>
<option value="7">9</option>
<option value="8">10</option>
<option value="9">11</option>
<option value="10">12</option>
<option value="11">13</option>
<option value="12">14</option>
<option value="13">15</option>
</select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save7"><i></i>Guardar
</button>
</div>
</form>
<form method="POST" action="http://laravel.dev/tournaments/1/categories/6/settings/9" accept-charset="UTF-8">
<div class="row">
<div class="col-md-2">
<label>
<input id="isTeam8" name="isTeam" type="hidden" value="0">
<input class="switch" data-on-text="Si" data-off-text="No" id="isTeam8" name="isTeam" type="checkbox" value="1">
</label>
</div>
<div class="col-md-5">
<select class="form-control" disabled="disabled" id="teamSize" name="teamSize">
<option value="0">2</option>
<option value="1">3</option>
<option value="2" selected="selected">4</option>
<option value="3">5</option>
<option value="4">6</option>
<option value="5">7</option>
<option value="6">8</option>
<option value="7">9</option>
<option value="8">10</option>
<option value="9">11</option>
<option value="10">12</option>
<option value="11">13</option>
<option value="12">14</option>
<option value="13">15</option>
</select>
</div>
</div>
<div align="right">
<button type="submit" class="btn btn-success save_category" id="save8"><i></i>Guardar
</button>
</div>
</form>

Your input element with id="teamSize" doesn't have a class called teamSize, thus your jQuery (which is looking for a class, not an id) has nothing to target.

Related

How can I pass <input> value into controller in Laravel?

I have a custom input field that acts as a drop-down menu and it works like this:
Each option is an <input> field and I need the value of this input to be passed into the controller. The <input> looks like this:
<!-- Updated -->
<label for="United States">United States</label>
<input type="radio" class="radio" id="United States" name="country" value="United States">
When the user presses the continue button, I want the value of the <input> to be passed to my controller: WelcomeController.
-- Updated --
My controller method looks like this:
public function countrySelect(Request $request)
{
$country = $request->input('country');
dd($country);
}
Here is a basic code structure of the inputs - I think I should be using a form and so have created a route in web.php:
Route::post('/', [\App\Http\Controllers\WelcomeController::class, 'countrySelect'])->name('CS');
And that the input should have the value property:
<!-- Updated -->
<form action="{{ route('CS') }}" method="POST">
<input name="country" value="[COUNTRY Value]">
<button type="submit"> CONTINUE </button>
</form>
The countrySelect method in my controller is empty and so how do I pass the value of the <input> into it? Thanks!
My Full Form:
<form action="{{ route('CS') }}" method="POST">
#csrf
<div class="country-select-container">
<div class="country-align-container">
<div class="CountryInput">
<div class="select-box">
<div class="options-container">
<div class="option">
<label for="United States">United States</label>
<input type="radio" name="country" value="United States">
</div>
<div class="option">
<label for="United Kingdom And Ireland">United Kingdom And Ireland</label>
<input type="radio" class="radio" id="United Kingdom And Ireland" name="country" value="United Kingdom And Ireland">
</div>
<div class="option">
<label for="Philippines">Philippines</label>
<input type="radio" name="country" value="Philippines">
</div>
<div class="option">
<label for="India">India</label>
<input type="radio" name="country" value="India">
</div>
<div class="option">
<label for="Indonesia">Indonesia</label>
<input type="radio" name="country" value="Indonesia">
</div>
<div class="option">
<label for="Malaysia">Malaysia</label>
<input type="radio" name="country" value="Malaysia">
</div>
<div class="option">
<label for="Mexico">Mexico</label>
<input type="radio" name="country" value="Mexico">
</div>
<div class="option">
<label for="Singapore">Singapore</label>
<input type="radio" name="Singapore">
</div>
<div class="option">
<label for="Germany">Germany</label>
<input type="radio" name="country" value="Germany">
</div>
<div class="option">
<label for="Brazil">Brazil</label>
<input type="radio" name="country" value="Brazil">
</div>
<div class="option">
<label for="Canada">Canada</label>
<input type="radio" name="country" value="Canada">
</div>
<div class="option">
<label for="Italy">Italy</label>
<input type="radio" name="country" value="Italy">
</div>
<div class="option">
<label for="Colombia">Colombia</label>
<input type="radio" name="country" value="Colombia">
</div>
<div class="option">
<label for="Australia">Australia</label>
<input type="radio" name="country" value="Australia">
</div>
<div class="option">
<label for="South Africa">South Africa</label>
<input type="radio" name="country" value="South Africa">
</div>
<div class="option">
<label for="France">France</label>
<input type="radio" name="country" value="France">
</div>
<div class="option">
<label for="Pakistan">Pakistan</label>
<input type="radio" name="country" value="Pakistan">
</div>
<div class="option">
<label for="Bangladesh">Bangladesh</label>
<input type="radio" name="country" value="Bangladesh">
</div>
<div class="option">
<label for="Spain">Spain</label>
<input type="radio" name="country" value="Spain">
</div>
<div class="option">
<label for="United Arab Emirates">United Arab Emirates</label>
<input type="radio" name="country" value="United Arab Emirates">
</div>
<div class="option">
<label for="Netherlands">Netherlands</label>
<input type="radio" name="country" value="Netherlands">
</div>
<div class="option">
<label for="Sri Lanka">Sri Lanka</label>
<input type="radio" name="country" value="Sri Lanka">
</div>
<div class="option">
<label for="Russia">Russia</label>
<input type="radio" name="country" value="Russia">
</div>
<div class="option">
<label for="Trinidad & Tobago">Trinidad & Tobago</label>
<input type="radio" name="country" value="Trinidad & Tobago">
</div>
<div class="option">
<label for="Saudi Arabia">Saudi Arabia</label>
<input type="radio" name="country" value="Saudi Arabia">
</div>
<div class="option">
<label for="Thailand">Thailand</label>
<input type="radio" name="country" value="Thailand">
</div>
<div class="option">
<label for="Peru">Peru</label>
<input type="radio" name="country" value="Peru">
</div>
<div class="option">
<label for="New Zealand">New Zealand</label>
<input type="radio" name="country" value="New Zealand">
</div>
<div class="option">
<label for="Vietnam">Vietnam</label>
<input type="radio" name="country" value="Vietnam">
</div>
<div class="option">
<label for="Japan">Japan</label>
<input type="radio" name="country" value="Japan">
</div>
<div class="option">
<label for="Egypt">Egypt</label>
<input type="radio" name="country" value="Egypt">
</div>
<div class="option">
<label for="Argentina">Argentina</label>
<input type="radio" name="country" value="Argentina">
</div>
<div class="option">
<label for="Other">Other...</label>
<input type="radio" name="country" value="Other...">
</div>
</div>
<div class="selected">
Select Country To Continue:
</div>
</div>
</div>
</div>
<div class="guest-action-container">
<div class="go-back-container">
<div class="go-back-btn">
<span class="go-back">
<span class="go-back-icon"></span>
<span class="go-back-text">BACK</span>
</span>
</div>
</div>
<div class="continue-to-site-container">
<div class="continue-to-site-btn">
<button type="submit" class="continue-to-site">
<span class="continue-text">CONTINUE</span>
<span class="continue-icon"></span>
</button>
</div>
</div>
<div class="clearFix"></div>
</div>
</div>
</form>
Here is the JS that creates the dropdown effect:
// country select drop down
$(document).ready(function(){
// country select options
const selected = document.querySelector(".selected");
const optionsContainer = document.querySelector(".options-container");
const optionsList = document.querySelectorAll(".option");
selected.addEventListener("click", () => {
optionsContainer.classList.toggle("active");
});
optionsList.forEach( o => {
o.addEventListener("click", () => {
selected.innerHTML = o.querySelector("label").innerHTML;
optionsContainer.classList.remove("active");
});
});
});
start by changing the code of the form from:
<form action="{{ route('CS') }}" method="POST">
<input value="country">
<button type="submit"> CONTINUE </button>
</form
to
<form action="{{ route('CS') }}" method="POST">
#csrf
<input value="country" name="country">
<button type="submit"> CONTINUE </button>
</form>
i hope that you are seeing the difference. while using a form in laravel you must and the csrf tokem if not i will not work.
After that in your controller just write:
public function handleSubmission(Request $request)
{
$country = $request->input('country');
}
In order to pass the value of an input to your controller you should start by having a "name" parameter in your input, then a POST route, in your web.php file, that calls the method in the controller that should get the values. Finally use request('name-of-input') and that should return the value.
Example:
view:
<form action="/user" class="admin-form" method="POST">
#csrf
<label for="form-name">Name: </label>
<input type="text" id="form-name" name="name" required>
<label for="form-email">Email: </label>
<input type="email" id="form-email" name="email" required>
<input id="form-submit" type="submit" value="Sign up!">
</form>
web.php:
Route::post('/user', 'App\Http\Controllers\UserController#store');
controller:
public function store(Request $request)
{
$user = new User();
$user->name = request('name');
$user->email = request('email');
$user->save();
return redirect('/user/create');
}
You need to include the name attribute in the input field like this:
<form action="{{ route('CS') }}" method="POST">
<input name="country" value="country">
<button type="submit"> CONTINUE </button>
</form
Then in the controller action you can reference the name field like this:
public function handleSubmission(Request $request)
{
$country = $request->input('country');
}

after clicking submit button a white page appears

I have made form using HTML n CSS and also linked action to my PHP file index_handler.php just don't understand where is the mistake that a strange white screen appears when I press submit
<form action="index_handler.php" class="appointment-form ftco-animate" method="post" name="form">
<div class="d-md-flex">
<div class="form-group">
<input type="text" class="form-control" name="name" placeholder="Full Name ">
</div>
<div class="form-group ml-md-4">
<input type="text" class="form-control" name="m_name" placeholder="Mother's Name">
</div>
<div class="form-group ml-md-4">
<input type="email" class="form-control" name="email" placeholder="Email ID">
</div>
</div>
<div class="d-md-flex">
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="course" id="" class="form-control">
<option value="text" style="color:black" >Select Course</option>
<option value="text" style="color:black" >Regular Classroom Programme</option>
<option value="text" style="color:black" >Distance Learning Programme</option>
<option value="text" style="color:black" >Online Learning Programme</option>
<option value="text" style="color:black" >School Integrated Programme</option>
<option value="text" style="color:black" >Crash Course Programme</option>
<option value="text" style="color:black" >Summer Course Programme</option>
<option value="text" style="color:black" >Edu-Nexus Programme</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="board" id="" class="form-control">
<option value="text" style="color:black" > Board</option>
<option value="text" style="color:black" >CBSE</option>
<option value="text" style="color:black" >CHSE(STATE)</option>
<option value="text" style="color:black" >ICSE</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="class" id="" class="form-control">
<option value="text" style="color:black" > Class</option>
<option value="text" style="color:black" >VI</option>
<option value="text" style="color:black" >VII</option>
<option value="text" style="color:black" >VIII</option>
<option value="text" style="color:black" >IX</option>
<option value="text" style="color:black" >X</option>
<option value="text" style="color:black" >XI</option>
<option value="text" style="color:black" >XII</option>
<option value="text" style="color:black" >XIII</option>
<option value="text" style="color:black" >Others</option>
</select>
</div>
</div>
</div>
</div>
<div class="d-md-flex">
<div class="form-group">
<textarea name="address" id="" cols="30" rows="2" class="form-control" placeholder="Address"></textarea>
</div>
<div class="form-group ml-md-4">
<input type="tel" name="phone" class="form-control" placeholder="Phone">
</div>
<div class="form-group ml-md-4">
<input type="submit" value="Request A Quote" class="btn btn-secondary py-3 px-4">
</div>
</div>
</form>
so here is my PHP file i.e, index_handler.php
<?php
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$m_name=$_POST['m_name'];
$course=$_POST['course'];
$board=$_POST['board'];
$class=$_POST['class'];
$address=$_POST['address'];
$phone=$_POST['phone'];
$to='rajkishore.panda2000#gmail.com';
$subject='Form Submission';
$message="Name :".$name."\n"."Mother's Name :".$m_name."\n"."Course :".$course."\n"."Board :".$board."\n"."Class :".$class."\n"."Phone :".$phone."\n"."Address:"."\n\n".$address;
$headers="From: ".$email;
if(mail($to, $subject, $message, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$name.", We will contact you shortly!</h1>";
}
else{
echo "<h1>Something went wrong!</h1>";
}
}
?>
You need give submit button name, because your php is
isset($_POST['submit'])
to fix your problem, change your code
<input type="submit" value="Request A Quote" class="btn btn-secondary py-3 px-4">
to
<input type="submit" name="submit" value="Request A Quote" class="btn btn-secondary py-3 px-4">
Hey just Add name="submit" and that's it
change this code
<div class="form-group ml-md-4">
<input type="submit" value="Request A Quote" class="btn btn-secondary py-3 px-4">
</div>
To be
<div class="form-group ml-md-4">
<input type="submit" name="submit" value="Request A Quote" class="btn btn-secondary py-3 px-4">
</div>

Submit same forms with two buttons and send thank you mail only on the second submit button

I am having the issue on submitting the same form with two submit buttons. I am submitting the form for the first time with ajax submission and on the second time I want to submit the whole form but when I send the form the thank you mail hits two times . I want to send the thank you mail only on the second submit button and not on the first button. I have the button type ="button" ,
Here is my form code:-
<form name="basicform" id="basicform" method="post" action="<?php bloginfo("template_directory"); ?>/forms/callback/callback_process.php">
<input type="hidden" value="<?php echo $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" name="source" id="source" />
<input type="hidden" value="submited" name="basicform"/>
<input type="hidden" name="form_name" id="form_name" value="Header Contact Form" class="basicformname" >
<div id="sf1" class="frm">
<fieldset>
<!--<legend>Take a step for a Good health.</legend>-->
<div class="wor-alert"><p class="text-center fill-fields">Please Fill All This Fields*</p></div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="travcure-icon travcure-user"></i></span>
<input type="text" placeholder="Name" id="uname" name="uname" class="form-control" autocomplete="off">
<span class="nameerr" id="unameerr"><?php echo #$_SESSION['unameerr'] ? $_SESSION['unameerr']:''; unset($_SESSION['unameerr']); ?></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="travcure-icon travcure-envelope"></i></span>
<input type="text" placeholder="Email" id="uemail" name="uemail" class="form-control" autocomplete="on">
<span class="emailerr" id="uemailerr"><?php echo #$_SESSION['uemailerr'] ? $_SESSION['uemailerr']:''; unset($_SESSION['uemailer']); ?></span>
</div>
</div>
<div class="form-group">
<input type="text" placeholder="Phone Number" id="uphone" name="uphone" class="uphone form-control" autocomplete="off">
<span class="phoneerr" id="uphoneerr"><?php echo #$_SESSION['uphoneerr'] ? $_SESSION['uphoneerr']:''; unset($_SESSION['uphoneerr']); ?></span>
<input type="hidden" class="uphonefull" name="uphonefull">
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="travcure-icon travcure-user-md"></i></span>
<span class="plain-select">
<select name="utreatments" data-style="btn-primary" id="utreatments" class="form-control selectpicker">
<option value="">Select Treatment</option>
<option value="Alternative Treatment">Alternative Treatment</option>
<option value="2">Treatment Two</option>
<option value="3">Treatment Three</option>
<option value="4">Treatment Four</option>
<option value="5">Treatment Five</option>
</select>
</span>
</div>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn open1" type="button" id="head-frm-btn">Next <span class="fa fa-arrow-right"></span></button>
</div>
</fieldset>
</div>
<div id="sf2" class="frm" style="display: none;">
<fieldset>
<!--<legend>What treatment are you looking for?</legend>-->
<div class="form-group">
<span class="plain-select">
<select name="ucity" id="ucity" class="form-control">
<option value="">Select City</option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
<option value="Banglore">Banglore</option>
<option value="Nagpur">Nagpur</option>
<option value="Goa">Goa</option>
</select>
</span>
</div>
<div class="form-group">
<span class="plain-select">
<select name="uhospital" id="uhospital" class="form-control">
<option value="">Select Hospital</option>
<option value="Hospital One">Hospital One</option>
<option value="Hospital Two">Hospital Two</option>
<option value="Hospital Three">Hospital Three</option>
<option value="Hospital Four">Hospital Four</option>
<option value="Hospital Five">Hospital Five</option>
</select>
</span>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn back2" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<button class="btn open2" type="button" id="head-frm-btn-two">Next <span class="fa fa-arrow-right"></span></button>
</div>
</fieldset>
</div>
<div id="sf3" class="frm" style="display: none;">
<fieldset>
<!--<legend>Almost done</legend>-->
<div class="waittext">
<p>Our customer care executive will get in contact with you soon. Please bear with us.</p>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn back3" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<input class="btn open3" value="Submit" type="submit" name="head_form_submit">
</div>
</fieldset>
</div>
</form>
I submit this form using ajax for the first submit button and then on the second button I send the whole information but I want to send the thank you mail on the second button and not on the ajax submission of the button. I want to get th email of both the forms but i want to send the thank you mail only on the second submit button.
you can use two submit buttons
<button type="submit" name="submit">Submit form</button>
<button type="submit" name="submit_and_send_email">Submit and Send Email</button>
in php you can access the post like this
<?php
if(isset($_POST['submit']))
{
//submit only
}
if(isset($_POST['submit_and_send_email']))
{
//submit and send email
}
?>

PHP email from submit and stay on page

Below is the code I'm using for my form. At the moment, when the form is submitted the message is shown on a separate page. I just want a message above the current form as appose to on a new page.
<div class="main_box">
<div class="clear"></div>
<div class="clear"></div>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="hidden" name="action" value="submit">
<div class="main_col">
<div class="main_col_left"><strong>BUSINESS NAME:</strong></div>
<div class="main_col_right">
<input type="text" name="business" id="business" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>EMAIL ADDRESS:</strong></div>
<div class="main_col_right">
<input type="text" name="email" id="email" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>PROPERTY PURCHASE PRICE:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="pur_price" id="pur_price" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>REFURB COST:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="refurb" id="refurb" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>Property Type :</strong></div>
<div class="main_col_right">
<select name="select2" id="select2" onchange="propType(this.value);">
<option value="">Select Property Type</option>
<option value="0.3">Car Showroom</option>
<option value="0.4">Care/Nursing Home</option>
<option value="0.25">Dental Surgery</option>
<option value="0.3">Department Store</option>
<option value="0.3">Distribution Centre</option>
<option value="0.3">FHL Apartment</option>
<option value="0.3">FHL House</option>
<option value="0.3">FHL Villa</option>
<option value="0.3">Hotel/B&B </option>
<option value="0.25">Industrial</option>
<option value="0.3">Industrial with Office</option>
<option value="0.3">Medical Centre</option>
<option value="0.25">Multi-Storey Car Park</option>
<option value="0.35">Nursery</option>
<option value="0.25">Office</option>
<option value="0.25">Office with Residential</option>
<option value="0.3">Petrol Station</option>
<option value="0.3">Public House</option>
<option value="0.3">Research Facility</option>
<option value="0.3">Restaurant</option>
<option value="0.25">Retail Warehouse</option>
<option value="0.3">Retail Shop</option>
<option value="0.3">Retail Shop & Office</option>
<option value="0.3">Shopping Centre</option>
<option value="0.3">Sports Centres</option>
<option value="0.3">Students Residence</option>
<option value="0.3">Theatre</option>
<option value="0.3">OTHER</option>
</select>
</div>
</div>
<div class="main_col" style="display:none">
<div class="main_col_left"><strong>AVERAGE CLAIM RATE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="avg_claim_rate" id="avg_claim_rate" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>AMOUNT CLAIMABLE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="amount_claim" id="amount_claim" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong> YOUR TAX RATE :</strong></div>
<div class="main_col_right">
<select name="tax_rate" id="tax_rate">
<option value=".24">24%</option>
<option value=".4">40%</option>
</select>
</div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"><strong>CLIENT TAX BENEFIT :</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><input type="text" name="client_benefit" id="client_benefit" value="" /></div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>INSTANT CASH RECLAIM:</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><input type="text" name="cash_reclaim" id="cash_reclaim" value="" /></div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>FUTURE TAX RELIEF :</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><!--<span id="future_tax_rel"></span>--> <input type="text" name="future_tax_rel" id="future_tax_rel" value="" /></div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<p style="line-height:20px;">Note : These figures are estimates and the final figures may very depending upon the property and full circusstances</p>
<div class="clear"></div>
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"> </div>
<div class="main_col_right">
<button onclick="calculate();">Calculate</button>
</div>
</div>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['business'];
$email=$_REQUEST['email'];
$pur_price=$_REQUEST['pur_price'];
$refurb=$_REQUEST['refurb'];
$select2=$_REQUEST['select2'];
$select=$_REQUEST['select'];
if (($name=="")||($email==""))
{
echo "Please enter business name & email";
}
else{
$from="Business : $name\r\nEmail : $email\r\nPurchase Price : $pur_price\r\nRefurb Cost : $refurb";
$subject="CTA Associates Calculator ";
mail("test#test.com", $subject, $from);
}
}
?>
<button onclick="reset();">Reset</button>
<div class="clear"></div>
<div class="clear"></div>
</div>
you can use something like this
<?php
if(isset($_GET['status']))
echo "success";
?>
end in the end of your code add header('Location:page.php?status')

Checked Checkbox Not Working?

I have an HTML form that posts to a PHP script. Everything is working except the checkbox. When it is checked, the value is not being posted.
HTML:
<input name="test" id="checkbox-02" type="checkbox" value="1" />
PHP:
if(!isset($_POST['test'])) {
$eventRepeat="No";
}
if(isset($_POST['test'])) {
$eventRepeat="Yes";
}
When this code runs, $eventRepeat always comes out as "No." I tried using the command "print_r($_POST)" and all inputs are posted except the checkbox, even when it is checked.
Any ideas what could cause this? I do have jQuery running so when it is checked two divs appear. Could that somehow be interfering? Here's the jQuery:
$(document).ready(function () {
$('#checkbox-02').change(function () {
if (!this.checked)
// ^
$('#repeatUntilDIV').fadeIn('slow');
$('#repeatFrequencyDIV').fadeIn('slow');
});
});
For reference, here is the full code:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="" method="post">
<div class="form-group">
<label for="inputEventTitle" class="col-lg-2 control-label">Event Title</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventTitle" placeholder="Event Title" required>
</div>
</div>
<div class="form-group">
<label for="inputEventDescription" class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventDescription" placeholder="Event Description" required>
</div>
</div>
<div class="form-group">
<label for="inputEventStartTime" class="col-lg-2 control-label">Start Time</label>
<div class="col-lg-10">
<select name="inputEventStartTime" class="form-control" id="dp1" required>
<option label="Start Time">
<option value="12:00AM">12:00AM</option>
<option value="12:15AM">12:15AM</option>
<option value="12:30AM">12:30AM</option>
<option value="12:45AM">12:45AM</option>
<option value="1:00AM">1:00AM</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEventEndTime" class="col-lg-2 control-label">End Time</label>
<div class="col-lg-10">
<select name="inputEventEndTime" class="form-control" id="dp1" required>
<option label="End Time">
<option value="1:00AM">1:00AM</option>
<option value="1:15AM">1:15AM</option>
<option value="1:30AM">1:30AM</option>
<option value="1:45AM">1:45AM</option>
<option value="2:00AM">2:00AM</option>
</select> </div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Date</label>
<div class="col-sm-6">
<input id="dp1" name="inputEventDate" type="text" size="16" class="form-control" required>
</div>
</div>
<div class="form-group">
<label for="inputEventDate" class="col-lg-2 control-label">Repeat?</label>
<div class="col-lg-10 checkboxes">
<label class="label_check" for="checkbox-02"> </label>
<input name="test" id="checkbox-02" type="checkbox" value="1" /> Yes, I want to repeat this event.
</div>
</div>
<div class="form-group" id="repeatUntilDIV" style="display:none;">
<label for="inputEventEndDate" class="col-lg-2 control-label">Repeat Until</label>
<div class="col-lg-10">
<input name="inputEventEndDate" id="eventEndDate" type="text" placeholder="End Date" class="form-control">
</div>
</div>
<div class="form-group" id="repeatFrequencyDIV" style="display:none;">
<label for="inputEventFrequency" class="col-lg-2 control-label">Repeat Every</label>
<div class="col-lg-10">
<select name="inputEventFrequency" class="form-control" id="dp1">
<option label="Repeat Every">
<option value="1">Repeat Every Day</option>
<option value="2">Repeat Every Other Day</option>
<option value="7">Repeat Every Week</option>
<option value="14">Repeat Every Other Week</option>
<option value="30">Repeat Every Month</option>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
<input type="submit" name="addPrimaryEvent" class="btn btn-success" value="Submit" />
</form>
I get this from var_dump($_POST):
array(8) {
["inputEventTitle"]=>
string(5) "Title"
["inputEventDescription"]=>
string(11) "Description"
["inputEventStartTime"]=>
string(6) "2:00AM"
["inputEventEndTime"]=>
string(6) "3:00AM"
["inputEventDate"]=>
string(10) "05-26-2014"
["inputEventEndDate"]=>
string(10) "05-29-2014"
["inputEventFrequency"]=>
string(1) "1"
["addPrimaryEvent"]=>
string(6) "Submit"
}
Very unclear why this would not work. But I noticed inconsistencies & imbalance in the HTML tags as well as an empty action="" which is not HTML5 valid. For more details, see this great answer over here.
So I have set it to #. You might want to actually change that to the full filename or path to the PHP script such as action="form.php". Or you could leave it out altogether like this:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="#" method="post">
But I prefer to be explicit & recommend the action="form.php" way of handling things. Here is your cleaned up HTML form:
<form class="cmxform form-horizontal tasi-form" id="commentForm" role="form" action="#" method="post">
<div class="form-group">
<label for="inputEventTitle" class="col-lg-2 control-label">Event Title</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventTitle" placeholder="Event Title" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventDescription" class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEventTitle" name="inputEventDescription" placeholder="Event Description" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventStartTime" class="col-lg-2 control-label">Start Time</label>
<div class="col-lg-10">
<select name="inputEventStartTime" class="form-control" id="dp1" required="">
<option value="12:00AM">
12:00AM
</option>
<option value="12:15AM">
12:15AM
</option>
<option value="12:30AM">
12:30AM
</option>
<option value="12:45AM">
12:45AM
</option>
<option value="1:00AM">
1:00AM
</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEventEndTime" class="col-lg-2 control-label">End Time</label>
<div class="col-lg-10">
<select name="inputEventEndTime" class="form-control" id="dp1" required="">
<option value="1:00AM">
1:00AM
</option>
<option value="1:15AM">
1:15AM
</option>
<option value="1:30AM">
1:30AM
</option>
<option value="1:45AM">
1:45AM
</option>
<option value="2:00AM">
2:00AM
</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">Date</label>
<div class="col-sm-6">
<input id="dp1" name="inputEventDate" type="text" size="16" class="form-control" required="" />
</div>
</div>
<div class="form-group">
<label for="inputEventDate" class="col-lg-2 control-label">Repeat?</label>
<div class="col-lg-10 checkboxes">
<input name="test" id="checkbox-02" type="checkbox" value="1" /> Yes, I want to repeat this event.
</div>
</div>
<div class="form-group" id="repeatUntilDIV" style="display:none;">
<label for="inputEventEndDate" class="col-lg-2 control-label">Repeat Until</label>
<div class="col-lg-10">
<input name="inputEventEndDate" id="eventEndDate" type="text" placeholder="End Date" class="form-control" />
</div>
</div>
<div class="form-group" id="repeatFrequencyDIV" style="display:none;">
<label for="inputEventFrequency" class="col-lg-2 control-label">Repeat Every</label>
<div class="col-lg-10">
<select name="inputEventFrequency" class="form-control" id="dp1">
<option value="1">
Repeat Every Day
</option>
<option value="2">
Repeat Every Other Day
</option>
<option value="7">
Repeat Every Week
</option>
<option value="14">
Repeat Every Other Week
</option>
<option value="30">
Repeat Every Month
</option>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button> <input type="submit" name="addPrimaryEvent" class="btn btn-success" value="Submit" />
</div>
</form>

Categories