Form is not submitting/Working - php

This form Submission is not working, Can anyone help me...
I am using bootstrap css and trying to submit a simple form, there is a small issue but I can't detect the problem, please help
<div class="container">
<div class="thumbs askus container col-md-6 col-md-offset-4">
<form id="logfrm" action="" method="post" class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-4">
<input type="text" name="unm" class="form-control" id="inputUser" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-4">
<input type="password" name="pwd" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button class="btn btn-default" >Sign in</button>
</div>
</div>
</form>
</div>
</div>
PHP Code for form handling
if (isset($_POST['unm'])) {
if ($_POST['unm']=="admin" && $_POST['pwd']=="xxxxxx") {
echo '<script type="text/javascript">alert("Hi Admin");</script>';
header('Location: home.php');
}
else{
echo '<script type="text/javascript">alert("Unknown Username/Bad password");</script>';
}
}

If your php for this form is on the same page, then it would make sense to direct the action to the same page. That way, the form will be sent to a refreshed version of the page where the PHP will pick it up and process it from there.
so - if you form is on a page called form.php
then it should be
<form id="logfrm" action="form.php" method="post" class="form-horizontal">
You can monitor the $_POST['umn'] using Firebug to see that everything is send properly

You just missed the action url so that the form submission does not working ... I just change the form action tag from action="" to action="action.php" where action.php is the file containing your php codes to handle the html form.Use the below Code this will solve your problem.
home.php
<?php
if(isset($_POST['submit_button']))
{
if ($_POST['unm']=="admin" && $_POST['pwd']=="xxxxxx") {
echo '<script type="text/javascript">alert("Ok");</script>';
header('Location:home.php');
}
else{
echo '<script type="text/javascript">alert("Unknown Username/Bad password"); if(confirm("Unknown Username/Bad password")){document.location.reload(true);}</script>';
}
}
else
{
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap 101 Template</title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
</head>
<body><br/><br/><br/><br/>
<div class="container">
<div class="thumbs askus container col-md-6 col-md-offset-4">
<form id="logfrm" method="post" class="form-horizontal" action="home.php">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Username</label>
<div class="col-sm-4">
<input type="text" name="unm" class="form-control" id="inputUser" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-4">
<input type="password" name="pwd" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button type="submit" class="btn btn-default" name="submit_button" >Sign in</button>
</div>
</div>
</form>
</div>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
</body>
<?php } ?>
</html>

Related

MySQL Database is not saving the data I insert but 0's [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a booking form and I successfully connected my database to my website. When I go to my database in MYSQL to see the data I inserted, all fields are in zeros. I tried changing my type of my data fields in the database but it didn't work.
My website connection with the MYSQL database:
<?php
$conexao=mysqli_connect("localhost", "root", "", "sitepap2");
?>
Code to sends the data inserted in the form to the database and to check if there's already a similar record in the database:
<?php
include("conecta.php");
$pnome=$_POST['pnome'];
$numerotmv=$_POST['numerotmv'];
$localsessao=$_POST['localsessao'];
$data=$_POST['data'];
$hora=$_POST['hora'];
$pesquisaUsuario = mysqli_num_rows(mysqli_query($conexao,"
SELECT nome FROM agendamento
WHERE numerotmv = '$numerotmv'
"));
if($pesquisaUsuario >0){
echo 1;
}else{
mysqli_query($conexao, "
insert into agendamento
(pnome, numerotmv, localsessao, data, hora)
values
('$pnome','$numerotmv', '$localsessao','$data','$hora')
");
echo 0;
}
?>
My index file where the form is displayed:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP form</title>
</head>
<body>
<div class="modal fade" id="calendario" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<!-- Registro -->
<form name="calendario" id="calendario" method="post" class="form-horizontal">
<div>
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="text-uppercase align-self-end text-center">Agendamento</h2>
<hr class="divider">
</div>
<div class="form-group">
<label class="control-label col-xs-4">Primeiro Nome</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="pnome" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Número de telemóvel</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="numerotmv" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Local da Sessão</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="localsessao" required="required">
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="data" type="date" required>
<span class="form-label">Data</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="hora" type="time" required>
<span class="form-label">Hora</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-4">
<button type="submit" onClick="verificarAgendamento()" class="btn btn-primary btn-lg">Agendar</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function verificarAgendamento(){
event.preventDefault();
$.ajax({
type: "POST",
url: "agendamento.php",
data: $("#calendario").serialize(),
success: function(resultado){
if(resultado==0){
alert("Booking made with success");
}else{
alert("error");
}
return false;
}
});
$('#calendario')[0].reset();
return false;
}
</script>
</body>
</html>
My database structure:
database
What happens when I try to insert data through my PHP form in the database:
problem
Thank to all the people that spent time reading this post to help me. I'm grateful.
You have two id's called calendario. The form and the div. So your ajax request is serializing the div, not the form.
Change one of the ids to a unique value and it will work e.g.:
NOTE: If you change the id of your form you need to change it in your ajax call as well
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP form</title>
</head>
<body>
<div class="modal fade" id="calendario" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<!-- Registro -->
<form name="calendario" id="calendario-form" method="post" class="form-horizontal">
<div>
<button type="button" class="close" data-dismiss="modal">×</button>
<h2 class="text-uppercase align-self-end text-center">Agendamento</h2>
<hr class="divider">
</div>
<div class="form-group">
<label class="control-label col-xs-4">Primeiro Nome</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="pnome" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Número de telemóvel</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="numerotmv" required="required">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-4">Local da Sessão</label>
<div class="col-xs-8">
<input type="text" class="form-control" name="localsessao" required="required">
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="data" type="date" required>
<span class="form-label">Data</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input class="form-control" name="hora" type="time" required>
<span class="form-label">Hora</span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-4">
<button type="submit" onClick="verificarAgendamento()" class="btn btn-primary btn-lg">Agendar</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
function verificarAgendamento(){
event.preventDefault();
$.ajax({
type: "POST",
url: "agendamento.php",
data: $("#calendario-form").serialize(),
success: function(resultado){
if(resultado==0){
alert("Booking made with success");
}else{
alert("error");
}
return false;
}
});
$('#calendario')[0].reset();
return false;
}
</script>
</body>
</html>

PHP form submission error

I created new inquiry form for my website. But it's giving the following error message.
Error
Sorry there was an error sending your form.
mail:Could not instantiate mail function.
Form HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP Contact Form Script With Validation - reusable form</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link rel="stylesheet" href="form.css" >
<script src="form.js"></script>
</head>
<body >
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<h2>Contact Us</h2>
<p> Send us your message and we will get back to you as soon as possible </p>
<form role="form" method="post" id="reused_form">
<div class="row">
<div class="col-sm-6 form-group">
<label for="name"> First Name:</label>
<input type="text" class="form-control" id="firstname" name="firstname" maxlength="50">
</div>
<div class="col-sm-6 form-group">
<label for="name"> Last Name:</label>
<input type="text" class="form-control" id="lastname" name="lastname" maxlength="50">
</div>
</div>
<div class="row">
<div class="col-sm-6 form-group">
<label for="email"> Email:</label>
<input type="text" class="form-control" id="email" name="email" maxlength="50">
</div>
<div class="col-sm-6 form-group">
<label for="email"> Phone:</label>
<input type="tel" class="form-control" id="phone" name="phone" required maxlength="50">
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<label for="name"> Message:</label>
<textarea class="form-control" type="textarea" id="message" name="message" placeholder="Your Message Here" maxlength="6000" rows="7"></textarea>
</div>
</div>
<div class="row">
<div class="col-sm-12 form-group">
<button type="submit" class="btn btn-lg btn-success btn-block" id="btnContactUs">Post It! </button>
</div>
</div>
</form>
<div id="success_message" style="width:100%; height:100%; display:none; "> <h3>Sent your message successfully!</h3> </div>
<div id="error_message" style="width:100%; height:100%; display:none; "> <h3>Error</h3> Sorry there was an error sending your form. </div>
</div>
</div>
</div>
</body>
</html>
Handler.php:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['firstname','lastname', 'email','phone'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->field('message')->maxLength(6000);
$pp->sendEmailTo('name#mail.com'); // ← Your email here
echo $pp->process($_POST);
You are not defining an action for the form.
<form role="form" method="post" id="reused_form" action="Handler.php">
<!-- html goes here -->
</form>

PHP Display single value from session array

I currently have a PHP form for our partners to register quotes. After the user log in they are brought to the beginning of the quote form. I would like the user's first name to display in the first form field automatically.
The user's session information includes an array of values; one of which is the firstName value. This is the value that I would like to display in the first field when the user logs in.
When I try to load the page I am getting an error instead of the user's first name.
This is the error I am getting:
Notice: Undefined index: user in C:\wamp64\www\quote_generator\quote_tool.php on line 77
Here is the updated page code:
<?php
require("config.php");
if(empty($_SESSION['user']))
{
header("Location: index.php");
die("Redirecting to index.php");
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Quoting Tool </title>
<meta name="description" content="Teo partner quote generator tool">
<meta name="Kenneth Carskadon" content="www.kencarskadon.com">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="assets/css/bootstrap.min.css" media="screen">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/3.1.3/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="assets/css/font-awesome/css/font-awesome.css">
<link rel="stylesheet" href="assets/css/form-elements.css">
<link rel="stylesheet" href="assets/css/datepicker.css">
<link rel="stylesheet" href="assets/css/style.css">
<style>
body {
background: url("assets/images/backgrounds/background.jpg") no-repeat fixed center;
background-size: cover;
}
</style>
</head>
<body>
<!-- Top menu -->
<nav class="navbar navbar-inverse navbar-no-bg" role="navigation">
<div class="container">
<div>
<a class="navbar-brand" href="#">
<img src="assets/images/logo/Teo%20Logo%20White.png" class="img-responsive" id="teo-logo">
</a>
</div>
</div>
</nav>
<!-- Top content -->
<div class="top-content">
<div class="inner-bg">
<div class="container form-container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text">
<h1><strong>Teo</strong> Partner Quote Generation Form</h1>
</div>
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-2 form-box">
<form role="form" action="" method="post" class="registration-form">
<!-- Fieldset 1: Partner Information -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Partner Information</h2>
<h3>Tell us who you are</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/partner_info.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="form-partner-name" placeholder="Partner name" class="form-partner-name form-control" id="form-partner-name"
value="<?php echo $_POST['user']['firstName']?>">
</div>
<div class="form-group">
<select name="partner-level" type="text" title="Select partner level" class="form-control" id="form-partner-level" >
<option>Select partner level</option>
<option data-price="34">Platinum</option>
<option data-price="32">Gold</option>
<option data-price="29">Silver</option>
</select>
</div>
<div class="form-group">
<input type="text" readonly="readonly" name="discount-perc" placeholder="Discount(%)" class="form-control" id="form-discount-perc">
</div><br />
<div class="form-group">
<input type="text" name="form-margin-perc" placeholder="Margin(%)" class="form-control" id="form-margin-perc">
</div>
<br /><br />
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<!-- Fieldset 2: Quote Information -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Quote Information</h2>
<h3>Tell us about your customer</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/partner_info.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<input type="text" name="form-customer-name" placeholder="Customer name" class="form-customer-name form-control" id="form-customer-name">
</div>
<div class="form-group">
<input type="text" name="form-quote-number" placeholder="Quote Number" class="form-quote-number form-control" id="form-quote-number">
</div>
<div class="form-group">
<input type="text" name="form-incentive-exp" placeholder="Incentive Expiration Date" class="teo-datepicker">
</div>
<div class="form-group">
<input type="text" name="form-proposal-exp" placeholder="Proposal Expiration Date" class="teo-datepicker">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
</div>
</fieldset>
<!-- Fieldset 3: Select Servers -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Select Servers</h2>
<h3>Tell us about the servers you need</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/select_servers.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label for="server-select">What kind of server do you need?</label>
<select class="form-control" id="server-type-select">
<option>Please select and option below</option>
<option>Pro Server</option>
<option>Mini Server</option>
</select>
</div>
<div class="form-group">
<label for="server-select">How many servers do you need?</label>
<input type="text" name="form-server-quantity" placeholder="Number of servers" class="form-control" id="form-server-quantity">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
<button type="button" class="btn btn-skip">skip</button>
</div>
</fieldset>
<!-- Fieldset 4: Configure Servers -->
<fieldset>
<div class="form-top">
<div class="form-top-left">
<h2>Select Servers</h2>
<h3>Tell us about the servers you need</h3>
</div>
<div class="form-top-right">
<img src="assets/images/icons/select_servers.png" class="form-icon">
</div>
</div>
<div class="form-bottom">
<div class="form-group">
<label for="server-select">What kind of server do you need?</label>
<select class="form-control" id="server-type-select">
<option>Please select and option below</option>
<option>Pro Server</option>
<option>Mini Server</option>
</select>
</div>
<div class="form-group">
<label for="server-select">How many servers do you need?</label>
<input type="text" name="form-server-quantity" placeholder="Number of servers" class="form-control" id="form-server-quantity">
</div>
<br /><br />
<button type="button" class="btn btn-previous">Previous</button>
<button type="button" class="btn btn-next">Next</button>
<button type="button" class="btn btn-skip">Skip</button>
</div>
</fieldset>
<div class="btn-logout">
Logout
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Javascript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/jquery.backstretch.min.js"></script>
<script type='text/javascript' src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>
<script src="assets/js/bootstrap-datepicker.js"></script>
<script src="assets/js/scripts.js"></script>
<!--[if lt IE 10]>
<script src="assets/js/placeholder.js"></script>
<![endif]-->
</body>
</html>
Update: I have a session page that shows me the information on the current session, and these are the results for the form I am talking about:
View Image
The screenshot clarified it.
You should be able to use
$session['user']['firstName']
As noted in the comments above though, you will want to migrate away from using eval, which has security implications.

Form_open in codeigniter not working

I've made a simple project in which a user can register his account, login with his credentials, view his blog posts and create a new blog. I'm currently working on creating a new blog which is simple a form with two options: blog title and content. I'm stuck with the part where you hit submit and the form is passed to the controller specified in form_open function. Nothing is happening when I hit the submit button, this is the issue.
Here is my view file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<meta charset="utf-8">
<title>Enter your Title</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<?=form_open("blog/submitpost"); ?>
<div class="form-horizontal">
<div class="form-group">
<label for="blogtitle" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<input type="text" name="blogtitle" placeholder="Enter your title here" class="form-control">
</div>
</div>
<div class="form-group">
<label for="blogdesc" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<textarea name="blogdesc" rows="8" cols="40" class="form-control" placeholder="Enter your post here"></textarea>
</div>
</div>
</div>
<?=form_close();?>
<div style="text-align: center;">
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</div>
</div>
</div>
</body>
</html>
And here is my controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('user');
$this->load->helper('form');
}
public function new_post($id){
$data['id'] = $id;
$this->load->view('blog_new_post',$data);
}
public function blogpostview($id){
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$data['id'] = $id;
$data['posts'] = $this->user->blog_post_list($data['username']);
$this->load->view('blog_view',$data);
}
public function submitpost(){
//there will be additional code here
$this->load->view('blog_post_view');
}
}
?>
Now firstly, I'm aware one has to load the Form helper class to achieve this, which I've already done. I've even changed the autoload.php file to automatically load it.
Secondly, I've already implemented this twice during registration and login processes. This time however I don't know why the code isn't working.
Okay I got the solution and it's a very simple one. I had not placed the submit button in the form due to which the problem was coming! Sometimes it's the simplest solutions that work out.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<meta charset="utf-8">
<title>Enter your Title</title>
</head>
<body>
<div class="container">
<div class="jumbotron">
<?php echo form_open("blog/submitpost"); ?>
<div class="form-horizontal">
<div class="form-group">
<label for="blogtitle" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<input type="text" name="blogtitle" placeholder="Enter your title here" class="form-control">
</div>
</div>
<div class="form-group">
<label for="blogdesc" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<textarea name="blogdesc" rows="8" cols="40" class="form-control" placeholder="Enter your post here"></textarea>
</div>
</div>
</div>
<div style="text-align: center;">
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</div>
<?=form_close();?>
</div>
</div>
</body>
</html>
try this
<?php
$attributes = array('name' => 'add_blog','id' => 'add_blog', 'method' =>'POST')
echo form_open("blog/submitpost", $attributes); ?> //form open
<?php echo form_close(); ?> //form close
Try this.....
<?php
$data = array('action' =>'blog/submitpost','id' => 'add_blog', 'method' =>'POST', )
echo form_open("blog/submitpost", $data); ?>
<div class="form-horizontal">
<div class="form-group">
<label for="blogtitle" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<input type="text" name="blogtitle" placeholder="Enter your title here" class="form-control">
</div>
</div>
<div class="form-group">
<label for="blogdesc" class="control-label col-sm-2">Blog Title</label>
<div class="col-sm-8">
<textarea name="blogdesc" rows="8" cols="40" class="form-control" placeholder="Enter your post here"></textarea>
</div>
</div>
</div>
<div style="text-align: center;">
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</div>
<?php echo form_close(); ?>

Why this modal form is getting redirected to my php file?

I have been trying to work with this form that I took from other website of mine, but it's not working in a new website I am creating.
What am I missing here? Maybe the form should be used different when is into a modal?
I just don't want to be redirected when submitting the form to the .php file. Any suggest?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Fincas Morales</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<!-- Custom fonts -->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
<link href="vendor/simple-line-icons/css/simple-line-icons.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css">
<!-- Custom styles for -->
<link href="css/landing-page.css" rel="stylesheet">
<!-- JQUERY CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<!-- The Modal -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Ingrese sus Datos:</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form id="cform" action="mailer1.php" method="post">
<div class="form-row">
<div class="col">
<input type="text" class="form-control" id="name" placeholder="Nombre" name="name">
</div>
<div class="col">
<input type="text" class="form-control" id="phone" placeholder="Teléfono" name="phone">
</div>
</div>
<div class="row mt-3">
<div class="col">
<input type="email" class="form-control" id="email" placeholder="Correo" name="email" required>
</div>
</div>
<div class="row mt-3">
<div class="col">
<input type="text" class="form-control" id="dim" placeholder="Dirección de inmueble" name="dim">
</div>
</div>
<div class="row mt-3">
<div class="col">
<input type="text" class="form-control" id="diudad" placeholder="Ciudad" name="ciudad">
</div>
<div class="col">
<input type="text" class="form-control" id="poblacion" placeholder="Población" name="poblacion">
</div>
</div>
<div class="row mt-3">
<div class="col">
<input type="text" class="form-control" id="viviendas" placeholder="N° Viviendas" name="viviendas">
</div>
<div class="col">
<input type="text" class="form-control" id="garajes" placeholder="N° Garajes" name="garajes">
</div>
<div class="col">
<input type="text" class="form-control" id="trasteros" placeholder="N° Trasteros" name="trasteros">
</div>
</div>
<div class="row mt-3">
<div class="col-4">
<input type="text" class="form-control" id="locales" placeholder="Locales" name="locales">
</div>
<div class="col-4">
<input type="text" class="form-control" id="ascensores" placeholder="Ascensores" name="ascensores">
</div>
<span class="mr-1">Portería:</span>
<div class="col-1 custom-control custom-radio">
<input type="radio" class="custom-control-input" id="r1" name="por" value="Si">
<label class="custom-control-label" for="r1">Sí</label>
</div>
<div class="col-1 custom-control custom-radio">
<input type="radio" class="custom-control-input" id="r2" name="por" value="No">
<label class="custom-control-label" for="r2">No</label>
</div>
</div>
<div class="row mt-3">
<div class="col">
<input type="text" class="form-control" id="asunto" placeholder="Asunto" name="asunto">
</div>
</div>
<div class="row mt-3">
<div class="col">
<textarea class="form-control" id="ozc" placeholder="Otras zonas comunes" name="ozc" rows="3"></textarea>
</div>
<div class="col">
<textarea class="form-control" id="mensaje" placeholder="Su Mensaje:" name="mensaje" rows="3"></textarea>
</div>
</div>
<div id="form-messages" class="mt-2 p-2 text-center success error" style="display:none;"></div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="submit" class="btn btn-success">Enviar</button>
</div>
</form>
</div>
</div>
</div>
<script src="app1.js"></script>
</body>
This is the .app1 file with the jQuery AJAX code:
$(function() {
// Get the form.
var form = $('#cform');
// Get the messages div.
var formMessages = $('#form-messages');
// Set up an event listener for the contact form.
$(form).submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
// Serialize the form data.
var formData = $(form).serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
})
.done(function(response) {
// Make sure that the formMessages div has the 'success' class.
$(formMessages).removeClass('error');
$(formMessages).addClass('success');
// Set the message text.
$(formMessages).text(response);
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#message').val('');
})
.fail(function(data) {
// Make sure that the formMessages div has the 'error' class.
$(formMessages).removeClass('success');
$(formMessages).addClass('error');
// Set the message text.
if (data.responseText !== '') {
$(formMessages).text(data.responseText);
} else {
$(formMessages).text('Oops! An error occured and
your message could not be sent.');
}
});
});
});
you can try
$("#cform").submit(....)
and for form data variable you can try
also
var formdata=new FormData(this);
another thing is to look your console to see if some bug appear
I don't see, any button or Js function to open the model by default.
So if you are getting the form view by running the index.html. It means your bootstrap.min.css is not loaded.
check your path to bootstrap.min.css
add the line to open the model on click
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
Everything looks fine till here. try and let me know. Please check the console while submitting.

Categories