Contact form doesn't send predefined values - javascript

I'm currently making a form wich works, but it doesn't send predefined values.
I have a few fields that I have predefined such as the user and total amount.
So it does send the values I enter, but not the ones that I have predefined
Can someone please help me, so that this thing can work as it should?
<?php require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: index.php'); }
?>
<html>
<head>
<title>*****</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="siteassets/assets/js/ie/hsiv.js"></script><![endif]-->
<link rel="stylesheet" href="siteassets/assets/css/main.css" />
<!--[if lte IE 8]><link rel="stylesheet" href="siteassets/assets/css/ie8.css" /><![endif]-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#next').keyup(calculate);
$('#nextprice').keyup(calculate);
$('#current').keyup(calculate);
$('#currentprice').keyup(calculate);
});
function calculate(e)
{
$('#total').val($('#next').val() * $('#nextprice').val() + $('#current').val() * $('#currentprice').val());
}
</script>
</head>
<body class="landing">
<div id="page-wrapper">
<!-- Header -->
<header id="header" class="alt">
<nav id="nav">
<ul>
<li>
Menu
<ul>
<li>Current Project</li>
<li>Next Projects</li>
<li>Previous Projects</li>
<li>Who are we?</li>
</ul>
</li>
<li>Tickets</li>
<li><a href='logout.php'>Logout</a></li>
</ul>
</nav>
</header>
<!-- Banner -->
<section id="banner">
<h2>********</h2>
<p>*******</p>
<ul class="actions">
<li>Current Project</li>
<li>Next Projects</li>
<li>Previous Projects</li>
<li>Who are we?</li>
<li>Tickets</li>
</ul>
</section>
<!-- Main -->
<section id="main" class="container 75%">
<div class="box">
<?
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(strlen($_POST['name2']) == 0)
{ $error_msg ="- Please, provide us with your name.<br>"; }
if(!empty($error_msg))
{
//Field error
echo "<b>Your message can't be send due to the following reason:</b><br><br>";
echo $error_msg;
echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with your name.<br><br>";
}
else
{
$recipient = "*********";
$subject = "******";
$header = "From: " . $_POST['uwemail'] . "\n";
$mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n";
$mail_body .= "De volgende persoon zou graag kaarten bestellen:\n\n";
$mail_body .= "Naam: " . $_POST['name2'] . "\n";
$mail_body .= "Met als kaartnummer: " . $_POST['card2'] . "\n";
$mail_body .= "Aantal kaarten voor de lopende productie: " . $_POST['current2'] . "\n";
$mail_body .= "Aantal kaarten voor de komende productie: " . $_POST['next2'] . "\n";
$mail_body .= "Voor een totaal: " . $_POST['total2'] . "\n";
$mail_body .= "\n\n -- Einde van het contact bericht --";
mail($recipient, $subject, $mail_body, $header);
print "<b>IMPORTANT!</b>";
print "<br><br>Thank you for your reservation.";
print "<br><br>Please note that this will be final upon receipt of payment of the total amount of";
print " POST TOTAAL";
print "EUR to Mazzini Theatre Productions";
print "<br><br>Confirmation of reservation and payment instruction details will be sent to you via email.";
print "<br><br>We are looking forward to meet you.";
}
}
else
{
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="contact">
<div class="row uniform 50%">
<div class="6u 12u(mobilep)">
Your personal card number
<input type="text" name="card2" id="card" value="<?php echo $_SESSION['username']; ?>" placeholder="Card Number" disabled/>
</div>
<div class="6u 12u(mobilep)">
Please enter your name. (mandatory)
<input type="text" name="name2" id="name" value="" placeholder="Your name" />
</div>
</div>
<div class="row uniform 50%">
<div class="6u 12u(mobilep)">
Current Project - Smile
<input type="text" name="current2" id="current" value="" placeholder="How many tickets would you like?" />
</div>
<div class="6u 12u(mobilep)">
Next Project - Sand
<input type="text" name="next2" id="next" value="" placeholder="How many tickets would you like?" />
</div>
</div>
<div class="row uniform 50%">
<div class="6u 12u(mobilep)">
<input type="hidden" id="currentprice" value="10" />
</div>
<div class="6u 12u(mobilep)">
<input type="hidden" id="nextprice" value="10" placeholder="" />
</div>
</div>
<div class="6u 12u(mobile)">
<input name="uwemail" placeholder="Email" type="hidden" value="**THIS WORKS**"/>
</div>
<div class="6u 12u(mobilep)">
Total price.(In EUR)
<input type="text" name="total2" id="total" value="" disabled/>
</div>
</div>
<div class="row uniform">
<div class="12u">
<ul class="actions align-center">
<li><input type="submit" name="submit"value="Place Order"/></li>
</ul>
</div>
</div>
</form>
<?php
}
?>
</div>
</section>
<!-- Footer -->
<footer id="footer">
<ul class="copyright">
<li>© **DISCLAIMER**</li>
</ul>
</footer>
</div>
<!-- Scripts -->
<script src="siteassets/assets/js/jquery.min.js"></script>
<script src="siteassets/assets/js/jquery.dropotron.min.js"></script>
<script src="siteassets/assets/js/jquery.scrollgress.min.js"></script>
<script src="siteassets/assets/js/skel.min.js"></script>
<script src="siteassets/assets/js/util.js"></script>
<!--[if lte IE 8]><script src="siteassets/assets/js/ie/respond.min.js"></script><![endif]-->
<script src="siteassets/assets/js/main.js"></script>
</body>
</html>

For your calculated fields you set attribute disabled. Fields with this attribute are not sent by form. Remove that attribute. You can set in that place readonly attribute

Forms do not send disabled fields. You alternatively can use readonly instead of disabled.

your hidden inputs are missing name= that's why they are not sent

Related

How to get the success message after clicking on submit button

I have my code where it should show a success message after submitting (click on add) but for some reason this success message is showing all the time even if I don't add anything, it is just showing on the top of the page.the problem is if I removed the message that is below if statement, the message will not show. the action is working fine it is just the success message. Can you please see what is the problem?
Add.php
<?php
include('header.php');
?>
<link rel="stylesheet" href="../../validation/dist/css/bootstrapValidator.css"/>
<script type="text/javascript" src="../../validation/dist/js/bootstrapValidator.js"></script>
<!-- =============================================== -->
<?php
include('../../form.php');
$frm=new formBuilder;
?>
<!-- =============================================== -->
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Add Coming Soon Movie
</h1>
<?php
if(isset($_SESSION['add']))
{?>
<div class="alert alert-success">
<strong>Success!</strong> News added successfully..
</div>
<?php
}?>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i> Home</li>
<li class="active">Add Coming Soon Movie</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-body">
<form action="process_add_news.php" method="post" enctype="multipart/form-data" id="form1">
<div class="form-group">
<label class="control-label">Movie name</label>
<input type="text" name="name" class="form-control"/>
<?php $frm->validate("name",array("required","label"=>"Movie Name")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<label class="control-label">Type</label>
<input type="text" name="type" class="form-control">
<?php $frm->validate("type",array("required","label"=>"Type","regexp"=>"text")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<label class="control-label">Release Date</label>
<input type="date" name="date" class="form-control"/>
<?php $frm->validate("date",array("required","label"=>"Release Date")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<label class="control-label">Description</label>
<input type="text" name="description" class="form-control">
<?php $frm->validate("description",array("required","label"=>"Description")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<label class="control-label">Images</label>
<input type="file" name="attachment" class="form-control" placeholder="Images">
<?php $frm->validate("attachment",array("required","label"=>"Image")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<label class="control-label">Trailer Youtube Link</label>
<input type="text" name="video" class="form-control"/>
<?php $frm->validate("video",array("label"=>"Image","max"=>"500")); // Validating form using form builder written in form.php ?>
</div>
<div class="form-group">
<button class="btn btn-success">Add Movie</button>
</div>
</form>
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
<?php
include('footer.php');
?>
<script>
<?php $frm->applyvalidations("form1");?>
</script>
processToAdd.php:
<?php
include('../../config.php');
extract($_POST);
$uploaddir = '../Coming-soon/';
$uploadfile = $uploaddir . basename($_FILES['attachment']['name']);
move_uploaded_file($_FILES['attachment']['tmp_name'],$uploadfile);
$flname="Coming-soon/".basename($_FILES["attachment"]["name"]);
mysqli_query($con,"INSERT INTO tbl_news values (NULL,'$name','$type','$date','$description','$flname','$video')");
$_SESSION['add']=1;
header('location:add_movie_news.php');
?>
I try this and found that, you need to start session
You just need to add session_start();
<?php
session_start();
if(isset($_REQUEST['submit_btn']))
{
$name = $_POST["names"];
$_SESSION['add'] = $name;
print_r($_SESSION);
}
?>
<html>
<head>
</head>
<body>
<?php
if(isset($_SESSION['add'])) {
?>
<div class="">
<strong>Success!</strong> News added successfully..
</div>
<?php
}
?>
<form action="" method="POST">
<input type="text" name="names" id="names">
<input type="submit" value="submit" name="submit_btn">
</form>
<script>
</script>
</body>
</html>
It seems like the issue is the line if(isset($_SESSION['add'])). So as long as $_SESSION['add'] is set the you have to see the message. Its either you unset it immediately after the message and reset it again on each button click or if the button you click is named 'submit', just use
if(isset($_POST['add'])){
//output message here
}
I try your code as example and remove validation and extra things
I also redirect Add.php to processToAdd.php and then again redirect processToAdd.php to Add.php
Please have a look and try this.
Hope this will resolve your problem.
Add.php:
<?php
session_start();
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
Add Coming Soon Movie
</h1>
<?php
if(isset($_SESSION['add'])) {
?>
<div class="alert alert-success">
<strong>Success!</strong> News added successfully..
</div>
<?php
}
?>
</section>
<!-- Main content -->
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-body">
<form action="processToAdd.php" method="post" enctype="" id="form1">
<div class="form-group">
<label class="control-label">Movie name</label>
<input type="text" name="name" class="form-control"/>
</div>
<div class="form-group">
<button class="btn btn-success" type="submit">Add Movie</button>
</div>
</form>
</div>
<!-- /.box-footer-->
</div>
<!-- /.box -->
</section>
<!-- /.content -->
</div>
processToAdd.php:
<?php
session_start();
extract($_POST);
$_SESSION['add']=1;
header('location:add.php');
?>

How to open a modal after form submission

I am making a site for my website and was wondering how to open the modal that the form is in after I submit the form. I am looking for it to open after I hit the submit button so I can see the errors that are put under the inputs or to show that it sent. I have tried to put the javascript inside the result if or else tag and it wont open the modal and just submits the form or presents the errors but you can't see them until you open the modal. So I was wondering how to open it backup after you submit it.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="FiveM roleplay server, with custom vehicles and scripts. Join today!">
<meta name="Keywords" content="aclfx, aclfxserver, fivem, fivem server, roleplay, gtav roleplay, gta v roleplay, fivem roleplay, fivem roleplay server, fort myers roleplay, fmrp, FMRP, fort myers rp">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../fmrp_test/styles/animate.css" rel="stylesheet" type="text/css">
<script
src="https://code.jquery.com/jquery-3.3.1.js"
integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/simplebar#latest/dist/simplebar.css" />
<script src="https://unpkg.com/simplebar#latest/dist/simplebar.js"></script>
<link href="https://fonts.googleapis.com/css?family=Overpass" rel="stylesheet">
<link href="../fmrp_test/styles/extra.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
<title>FMRP | Applications</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="../fmrp_test/index.html">FMRP</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse ml-auto" id="navbarNav">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="https://www.fortmyersrp.net/forum/">Forums</a>
</li>
<li class="nav-item">
<a class="nav-link" href="../fmrp_test/help.php">Help</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../fmrp_test/applications_menu.php">Applications <span class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</div>
</nav>
<br><br>
<div class="container">
<p>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
<h1 class="title text-center" id="staff">Staff Member Application (Moderator):</h1>
<?php
if (isset($_POST["submit"])) {
$fullname = $_POST['fullname'];
$age = $_POST['age'];
$discord = $_POST['discord'];
$timezone = $_POST['timezone'];
$roleplaydescription = $_POST['roleplaydescription'];
$experence = $_POST['experence'];
$to = 'blakecharlie239#gmail.com';
$subject = 'Staff Form';
$body = "From: $fullname\n Age: $age\n Discord: $discord\n Timezone: $timezone\n How long have you roleplayed: $roleplaydescription\n Past staff experience: $experence";
// Check if name has been entered
if (!$_POST['fullname']) {
$errName = 'Please enter your full name.';
}
// Check if email has been entered and is valid
//Check if message has been entered
if (!$_POST['age']) {
$errage = 'Please enter your age.';
}
if (!$_POST['discord']) {
$errdiscord = 'Please enter your discord tag.';
}
if (!$_POST['timezone']) {
$errtimezone = 'Please enter your timezone.';
}
if (!$_POST['roleplaydescription']) {
$errroleplaydescription = 'Please enter if you have roleplayed before.';
}
if (!$_POST['experence']) {
$errexperence = 'Please enter your level of staff experience.';
}
// If there are no errors, send the email
if (!$errName && !$errage && !$errdiscord && !$errtimezone && !$errroleplaydescription && !$errexperence) {
if (mail ($to, $subject, $body)) {
$result='<div class="alert alert-success">Thank you for the application! Please allow 4-36 hours from the time of submission for a response. Please do not resubmit an application if we do not respond within that timeframe; we may have other priorities.</div>';
} else {
$result='<div class="alert alert-danger">We are sorry, but there was an error sending your message; please try again. If the error keeps occurring, please pm Spartan78942#0877 on discord for help resolving this.</div>';
} echo "<script>
$('.collapse').css('display', 'show !important');
</script>";
}
}
?>
<?php echo "<p class='text-danger'>$result</p>";?>
<div class="row">
<div class="col-md-12 col-lg-12"> <form action="applications_menu.php" method="post">
<div class="form-group">
<label for="exampleInputEmail1">First & last name:</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter your first & last name here." name="fullname">
<?php echo "<p class='text-danger'>$errName</p>";?>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Age (MIN 16):</label>
<input type="number" class="form-control" id="exampleInputPassword1" placeholder="Enter your age here." name="age">
<?php echo "<p class='text-danger'>$errage</p>";?>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Discord:</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter your discord tag here. Should look like this: [name]#[4 digits] Ex: aclfx#8109" name="discord">
<?php echo "<p class='text-danger'>$errdiscord</p>";?>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Timezone:</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter your timezone here." name="timezone">
<?php echo "<p class='text-danger'>$errtimezone</p>";?>
</div>
<div class="form-group">
<label for="exampleInputEmail1">How long have you roleplayed?:</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter how long have you been roleplaying." name="roleplaydescription">
<?php echo "<p class='text-danger'>$errroleplaydescription</p>";?>
</div>
<div class="form-group">
<label for="exampleInputEmail1">Past staff experience:</label>
<input type="text" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter and describe your past staff experience." name="experence">
<?php echo "<p class='text-danger'>$errexperence</p>";?>
</div>
<br>
<div class="row"><div class="col-lg-12"><button type="submit" name="submit" value="send" class="subbut btn btn-primary mx-auto d-block" style="width: 190px !important;height: 60px !important;font-size: 25px;">Submit</button></div></div></form>
</div>
</div></div>
</div>
</div>
</div>
</body>
</html>
Just add the following code before closing your body tag
It checks if form submitted and if its submitted it adds a javascript code which triggers collapse which shows your form response or errors.
<?php if(isset($_POST['submit'])){
?>
<script type="text/javascript">
jQuery('#collapseExample').collapse({
toggle:true
})
</script>
<?php
}?>
First, your javascript is targeting multiple elements since you use collapse in the navbar too. You need to target #collapseExample instead.
Second, you have to add the show class to the element, not set its display property.
So the proper js is:
$('#collapseExample').addClass('show');
You also have the script inside the "no errors" condition, so it won't run.
And you can do this in php if you want. Move your error checking before the form and if there's any error set a variable.
<?php
if ($errName || $errage) // Boilerplate to set the error
$error = true;
?>
<div class="collapse<?= $error ? ' show' : '' ?>" id="collapseExample">
Hope this is what you are looking for, since I can find no modal in your code.

Dynamic html form values are not being stored in database

I am developing a game portal in which professor should be able to add any type of questions in a game. I have created the question type(multiple choice or descriptive ) functions in form.php and i am calling them in my main file. First of all in the loop I am calling main box(simple html box) in which i have to add the question. And its working fine. Now i have to store the dynamically changed boxes values in database. But i don't know where i am wrong. Following is my form.php in which i am creating forms to call in the main file.
<?
$i=$_post['i'];
$_SESSION["input_type"][$i]= $_POST["type"];
if($_SESSION["input_type"][$i]==1)
{
form($i);
}
elseif($_SESSION["input_type"][$i]==2)
{
form1();
}
function form($i)
{
?>
<div class="control-group">
<div class="controls">
<textarea class="large m-wrap" placeholder=" Statement " cols="50"rows="3" name="statement<?echo $i;?>" style="text-align:center;" id="statement<?echo $i;?>"></textarea>
</div>
</div>
<div class="name">
<input name="option<?echo $i.'1';?>" id="option<?echo $i.'1';?>" placeholder="Option 1" style="width:170px;" type="text"/>
<input name="option<?echo $i.'2';?>" id="option<?echo $i.'2';?>" type="text" style="width:170px;" placeholder="Option 2"/>
<input name="option<?echo $i.'3';?>" id="option<?echo $i.'3';?>" type="text" style="width:170px;" placeholder="Option 3"/>
<input name="option<?echo $i.'4';?>" id="option<?echo $i.'4';?>" type="text" style="width:170px;" placeholder="Option 4"/>
</div>
<div class="control-group">
<div class="controls">
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<label class="radio">
<input type="radio" name="option<?echo $i.'1';?>_default" id="option<?echo $i.'1';?>_default" />
Option 1
</label>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<label class="radio">
<input type="radio" name="option<?echo $i.'2';?>_default" id="option<?echo $i.'2';?>_default" checked />
Option 2
</label>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<label class="radio">
<input type="radio" name="option<?echo $i.'3';?>_default" id="option<?echo $i.'3'?>_default" />
Option 3
</label>
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
<label class="radio">
<input type="radio" name="option<?echo $i.'4';?>_default" id="option<?echo $i.'4';?>_default" />
Option 4
</label>
</div>
</div>
<?php
}
//end
?>
<?php
function form1()
{ ?>
<div class="control-group" id ="field" name="field">
<label class="control- label">Answer</label>
<div class="controls">
<input type="text" placeholder="Answer" id ="ans" name="ans" class="m-wrap small" />
</div>
</div>
<?
}
?>
This is my main file in which i am cakking the form.php functions to add questions
<!-- BEGIN PAGE -->
<div class="page-content">
<form action="storeGame.php" method="POST">
<div class="control-group">
<label class="control-label">Game Name</label>
<div class="controls">
<input type="text" id="game_name" name="game_name" placeholder="Enter Game Name" class="m-wrap large" />
</div>
</div>
<!-- BEGIN BORDERED TABLE PORTLET-->
<?
$q_no=5;
for ($i=0;$i<$_SESSION["q_inc"]; $i++)
{
?>
<div class="portlet box yellow">
<div class="portlet-title">
<h4><i class="icon-coffee"></i>#<?echo $i+1;?> </h4>
<div class="tools">
</div>
</div>
<div class="portlet-body">
<table class="table table-bordered table-hover">
<thead>
</thead>
<tbody>
<form action="newGame.php" method="POST" id="input_type" name="input_type">
<div class="control-group">
<label class="control-label" > Add Input</label>
<div class="controls">
<select class="medium m-wrap question_type" data-question-no="<?echo $i;?>" tabindex="1" id="type<?echo $i;?>" name="type<?echo $i;?>">
<option value="">Input Type</option>
<option value="1">Multiple Choice</option>
<option value="2">Input Field</option>
</select>
</div>
<div id="answer_no_<?php echo $i ?>"></div>
</div>
</form>
</tbody>
</table>
</div>
</div>
<script>
$(document).ready(function(){
$('.question_type').change(function(){
var question_no=$(this).attr('data-question-no');
$.ajax({
url: "form.php",
type:'post',
data:{
type:$(this).val(),
i:question_no
},
success:function(data){
$('#answer_no_'+question_no).html(data);
}
});
});
});
</script>
<?
}
?>
<!-- END BORDERED TABLE PORTLET-->
<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
<!-- BEGIN PAGE HEADER-->
<div class="row-fluid">
<div class="span12">
<!-- BEGIN STYLE CUSTOMIZER -->
<div class="color-panel hidden-phone">
<div class="color-mode-icons icon-color"></div>
<div class="color-mode-icons icon-color-close"></div>
<div class="color-mode">
<p>THEME COLOR</p>
<ul class="inline">
<li class="color-black current color-default" data-style="default"></li>
<li class="color-blue" data-style="blue"></li>
<li class="color-brown" data-style="brown"></li>
<li class="color-purple" data-style="purple"></li>
<li class="color-white color-light" data-style="light"></li>
</ul>
<label class="hidden-phone">
<input type="checkbox" class="header" checked value="" />
<span class="color-mode-label">Fixed Header</span>
</label>
</div>
</div>
<!-- END BEGIN STYLE CUSTOMIZER -->
<!-- BEGIN PAGE TITLE & BREADCRUMB-->
<h3 class="page-title">
</h3>
<!-- END PAGE TITLE & BREADCRUMB-->
</div>
</div>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<div class="row-fluid">
<div class="span12" >
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<input type="hidden" id="session" data="#Request.RequestContext.HttpContext.Session['questNo']" />
<!-- <a class="btn green" type="submit" ><i class="icon-plus" ></i></a> -->
<button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>
</form>
</div>
<!-- END PAGE CONTENT-->
</div>
<!-- END PAGE CONTAINER-->
<button type="submit" class="btn yellow btn-block" id="getGames" name="getGames" class="btn green">Create Game <i &nbsp class="m-icon-big-swapright m-icon-white"></i></button>
</form>
</div>
</div>
<!-- END PAGE -->
And below is my storeGame.php file in which i am getting values of question fields and saving in the database but the dynamic box values are not being saved but all other box values are being saved.
<?
session_start();
include_once("../Includes/db_connection.php");
$lecturer_id = $_SESSION["lecturer_id"];
$game_name=mysql_real_escape_string($_POST['game_name']);
echo $_SESSION["lecturer_id"];;
echo $game_name;
mysql_query("insert into games(game_name, lecturer_id) values ('$game_name', '$lecturer_id')");
for($i=0;$i<$_SESSION["q_inc"];$i++)
{
$input_type = mysql_real_escape_string($_POST['type'.$i]);
if($input_type=='1')
{
$question= $_POST['statement'.$i];
$val1= $_POST['option'.$i.'1'];
$val2= $_POST['option'.$i.'2'];
$val3= $_POST['option'.$i.'3'];
$val4= $_POST['option'.$i.'4'];
$default1= $_POST['option'.$i.'1'.'_default'];
$default2= $_POST['option'.$i.'2'.'_default'];
$default3= $_POST['option'.$i.'3'.'_default'];
$default4= $_POST['option'.$i.'4'.'_default'];
mysql_query("insert into subgames(game_id, input_id, statement, option1, option2, option3, option4, default1, default2, default3, default4) values ((SELECT id
FROM games WHERE game_name = '$game_name'), '$input_type', '$question', '$val1', '$val2', '$val3', '$val4', '$default1', '$default2', '$default3', '$default4')");
$error= mysql_error();
}
elseif($input_type=='2')
{
$question= $_POST['quest'];
$answer= $_POST['ans'];
// it is not implemented so leave it
}
}
Kindly help me i have tried a lot but i don't know where i am wrong. Thanks in advance
First of all I want to tell you that there are lots of problem in your code. Those I got are as follows.
1: There is no need to paste the entire html code of header and footer as well. This causes to skipped from the people who can give you answer, they run away after seeing lots of code. i.e. unnecessary.
2: You have defined multiple form tags, and these forms are nested to each other. every form should be closed before opening any other form tag.
3: Radio button tag's name should have the same for every group of the option, their value should be different not the name. for example for gender there should be two radio input tag with same name name="gender" and with different value like value="male" & value="female". you'll get the only one value for the radio button with same name.
4: if you are going to use session anywhere on the page, it first of all should be started before printing any output.
5: You have not given any value for the default value of radio button. So there should be a value attribute with different value inside that
6: whenever you are going to name a funtion, name it according to its functionality, not like a, b, c. Here I'm going to change your form to form_multiple() and form1 to form_input()
7: when you are going to choose input field for more than one question, then you'll have two input field with the same name, that is not allowed. So, let here also pass the i to the function.
====================
here is the solution for your code.
1: I have removed the numbers from default in radio button.
form.php
<?php
$i = $_POST['i'];
$_SESSION["input_type"][$i] = $_POST["type"];
if ($_SESSION["input_type"][$i] == 1) {
form_multiple($i);
} elseif ($_SESSION["input_type"][$i] == 2) {
form_input($i);
}
function form_multiple($i)
{
?>
<div class="control-group">
<div class="controls">
<textarea class="large m-wrap" placeholder=" Statement " cols="50" rows="3" name="statement<?php echo $i; ?>" style="text-align:center;" id="statement<?php echo $i; ?>"></textarea>
</div>
</div>
<div class="name">
<input name="option<?php echo $i . '1'; ?>" id="option<?php echo $i . '1'; ?>" placeholder="Option 1"
style="width:170px;" type="text"/>
<input name="option<?php echo $i . '2'; ?>" id="option<?php echo $i . '2'; ?>" type="text" style="width:170px;"
placeholder="Option 2"/>
<input name="option<?php echo $i . '3'; ?>" id="option<?php echo $i . '3'; ?>" type="text" style="width:170px;"
placeholder="Option 3"/>
<input name="option<?php echo $i . '4'; ?>" id="option<?php echo $i . '4'; ?>" type="text" style="width:170px;"
placeholder="Option 4"/>
</div>
<div class="control-group">
<div class="controls">
Choose Default Option
<br/>
<label class="radio">
<input type="radio" value="1" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '1'; ?>_default"/>
Option 1
</label>
<br/>
<label class="radio">
<input type="radio" value="2" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '2'; ?>_default"
checked />
Option 2
</label>
<br/>
<label class="radio">
<input type="radio" value="3" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '3' ?>_default"/>
Option 3
</label>
<br/>
<label class="radio">
<input type="radio" value="4" name="option<?php echo $i; ?>_default" id="option<?php echo $i . '4'; ?>_default"/>
Option 4
</label>
</div>
</div>
<?php
}
//end
?>
<?php
function form_input($i)
{
?>
<div class="control-group" id="field" name="field">
<label class="control- label">Answer</label>
<div class="controls">
<input type="text" placeholder="Answer" id="ans" name="ans_<?php echo $i; ?>" class="m-wrap small"/>
</div>
</div><?php
}
?>
=====================================
In the below page I have removed some of the tags to shorten the answer
and I also have commented the form tags, so that you can analyze your errors. These two forms were inside another form tag
I don't know where you have defined $_SESSION["q_inc"] variable. I assume that this variable will have some integer value inside.
main content page
<?php
session_start();
include_once("../Includes/db_connection.php");
//include_once("form.php");
if(isset($_POST['total_q'])){
$_SESSION["q_inc"]=$_POST['total_q'];
}
if (!isset($_SESSION["q_inc"])) {
$_SESSION["q_inc"] = 2;
}
$_SESSION["questNo"] = $_SESSION["q_inc"];
if (!isset($_SESSION["lecturer_id"])) {
header("Location:../login.php");
}
//if($_SERVER['add_q'] == 'POST')
//$counter=0;
if (isset($_POST['add_q'])) {
$_SESSION["q_inc"]++;
}
?>
<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<script type="text/javascript" src="../includes/jquery.js"></script>
<meta charset="utf-8"/>
<title>ClassEx</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<meta content="" name="description"/>
<meta content="" name="author"/>
<link href="../assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
<link href="../assets/css/metro.css" rel="stylesheet"/>
<link href="../assets/bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet"/>
<link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet"/>
<link href="../assets/fullcalendar/fullcalendar/bootstrap-fullcalendar.css" rel="stylesheet"/>
<link href="../assets/css/style.css" rel="stylesheet"/>
<link href="../assets/css/style_responsive.css" rel="stylesheet"/>
<link href="../assets/css/style_default.css" rel="stylesheet" id="style_color"/>
<link rel="stylesheet" type="text/css" href="../assets/chosen-bootstrap/chosen/chosen.css"/>
<link rel="stylesheet" type="text/css" href="../assets/uniform/css/uniform.default.css"/>
<link rel="shortcut icon" href="../assets/img/favicon.ico"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="fixed-top">
<!-- BEGIN HEADER -->
<div class="header navbar navbar-inverse navbar-fixed-top">
<!-- BEGIN TOP NAVIGATION BAR -->
<div class="navbar-inner">
<div class="container-fluid">
<!-- BEGIN LOGO -->
<a class="brand" href="#">
<img src="../assets/img/logoclassex.jpg" alt="logo" height="35px" width="35px""/>
</a>
<!-- END LOGO -->
<!-- BEGIN RESPONSIVE MENU TOGGLER -->
<a href="javascript:;" class="btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse">
<img src="../assets/img/menu-toggler.png" alt=""/>
</a>
<!-- END RESPONSIVE MENU TOGGLER -->
<!-- BEGIN TOP NAVIGATION MENU -->
<ul class="nav pull-right">
<!-- BEGIN NOTIFICATION DROPDOWN -->
<!-- END NOTIFICATION DROPDOWN -->
<!-- BEGIN INBOX DROPDOWN -->
<!-- END INBOX DROPDOWN -->
<!-- BEGIN TODO DROPDOWN -->
<!-- END TODO DROPDOWN -->
</ul>
<!-- END TOP NAVIGATION MENU -->
</div>
</div>
<!-- END TOP NAVIGATION BAR -->
</div>
<!-- END HEADER -->
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
<!-- BEGIN SIDEBAR -->
<div class="page-sidebar nav-collapse collapse">
<!-- BEGIN SIDEBAR MENU -->
<ul>
<li>
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
<div class="sidebar-toggler hidden-phone"></div>
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
</li>
<li class="start ">
<a href="lecturer.php">
<i class="icon-home"></i>
<span class="title">Dashboard</span>
</a>
</li>
<li class="">
<a href="../includes/logout.php">
<i class=" icon-off"></i>
<span class="title">Logout</span>
</a>
</li>
</ul>
<!-- END SIDEBAR MENU -->
</div>
<!-- END SIDEBAR -->
<!-- BEGIN PAGE -->
<div class="page-content">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" >
<input type="hidden" id="session" data="#Request.RequestContext.HttpContext.Session['questNo']" />
<!-- <a class="btn green" type="submit" ><i class="icon-plus" ></i></a> -->
Enter no of question<input name="total_q" type="text" />
<input type="submit" />
<!--<button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>-->
</form>
<form action="storeGame.php" method="POST">
<div class="control-group">
<label class="control-label">Game Name</label>
<div class="controls">
<input type="text" id="game_name" name="game_name" placeholder="Enter Game Name"
class="m-wrap large"/>
</div>
</div>
<!-- BEGIN BORDERED TABLE PORTLET-->
<?php
$q_no = 5;
for ($i = 0; $i < $_SESSION["q_inc"]; $i++) {
$temp = $i;
?>
<div class="portlet box yellow">
<div class="portlet-title">
<h4><i class="icon-coffee"></i>#<?php echo ($temp + 1); ?></h4>
<div class="tools">
</div>
</div>
<div class="portlet-body">
<table class="table table-bordered table-hover">
<div class="control-group">
<label class="control-label"> Add Input</label>
<div class="controls">
<select class="medium m-wrap question_type" data-question-no="<?php echo $i; ?>"
tabindex="1" id="type<?php echo $i; ?>" name="type<?php echo $i; ?>">
<option value="">Input Type</option>
<option value="1">Multiple Choice</option>
<option value="2">Input Field</option>
</select>
</div>
<div id="answer_no_<?php echo $i; ?>"></div>
</div>
</tbody>
</table>
</div>
</div>
<?php
}
?>
<script>
$(document).ready(function () {
$('.question_type').change(function () {
var question_no = $(this).attr('data-question-no');
$.ajax({
url: "form.php",
type: 'post',
data: {
type: $(this).val(),
i: question_no
},
success: function (data) {
$('#answer_no_' + question_no).html(data);
}
});
});
});
</script>
<!-- END BORDERED TABLE PORTLET-->
<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
<!-- BEGIN PAGE CONTENT-->
<div class="row-fluid">
<div class="span12">
<!-- <form action="-->
<?php //echo $_SERVER['PHP_SELF']; ?><!--" method="POST" >-->
<!-- <input type="hidden" id="session" data="#Request.RequestContext.HttpContext.Session['questNo']" />-->
<!-- <button type="submit" id="add_q" name="add_q" class="btn green"><i class="icon-plus"></i></button>-->
<!-- </form>-->
</div>
<!-- END PAGE CONTENT-->
</div>
<!-- END PAGE CONTAINER-->
<button type="submit" class="btn yellow btn-block" id="getGames" name="getGames" class="btn green">
Create Game <i &nbsp class="m-icon-big-swapright m-icon-white"></i></button>
</form>
</div>
</div>
<!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<!-- BEGIN FOOTER -->
<div class="footer">
University of Passau ClassEx Team
<div class="span pull-right">
<span class="go-top"><i class="icon-angle-up"></i></span>
</div>
</div>
<!-- END FOOTER -->
<!-- BEGIN JAVASCRIPTS -->
<!-- Load javascripts at bottom, this will reduce page load time -->
<script src="../assets/js/jquery-1.8.3.min.js"></script>
<script src="../assets/breakpoints/breakpoints.js"></script>
<script src="../assets/jquery-slimscroll/jquery-ui-1.9.2.custom.min.js"></script>
<script src="../assets/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/js/jquery.blockui.js"></script>
<script src="../assets/js/jquery.cookie.js"></script>
<script src="../assets/fullcalendar/fullcalendar/fullcalendar.min.js"></script>
<script type="text/javascript" src="../assets/uniform/jquery.uniform.min.js"></script>
<script type="text/javascript" src="../assets/chosen-bootstrap/chosen/chosen.jquery.min.js"></script>
<!-- ie8 fixes -->
<!--[if lt IE 9]>
<script src="../assets/js/excanvas.js"></script>
<script src="../assets/js/respond.js"></script>
<![endif]-->
<script src="../assets/js/app.js"></script>
<script>
jQuery(document).ready(function () {
// initiate layout and plugins
App.setPage('calendar');
App.init();
});
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>
===============================
There should be only one default option field in the database. Here I have removed all those and added one named "default_option"
storeGame.php
<?php
session_start();
include_once("../Includes/db_connection.php");
$lecturer_id = $_SESSION["lecturer_id"];
$game_name=mysql_real_escape_string($_POST['game_name']);
echo $_SESSION["lecturer_id"];;
echo $game_name;
$sql="insert into games(game_name, lecturer_id) values ('$game_name', '$lecturer_id')";
if(!mysql_query($sql)){
echo "Error in storing into database!<br/>";
}
for($i=0;$i<$_SESSION["q_inc"];$i++)
{
$input_type = mysql_real_escape_string($_POST['type'.$i]);
if($input_type=='1')
{
$question= $_POST['statement'.$i];
$val1= $_POST['option'.$i.'1'];
$val2= $_POST['option'.$i.'2'];
$val3= $_POST['option'.$i.'3'];
$val4= $_POST['option'.$i.'4'];
//Here should be only one default value
$default_option= $_POST['option'.$i.'_default'];
/*$default1= $_POST['option'.$i.'1'.'_default'];
$default2= $_POST['option'.$i.'2'.'_default'];
$default3= $_POST['option'.$i.'3'.'_default'];
$default4= $_POST['option'.$i.'4'.'_default'];*/
$sql=" insert into subgames( game_id, input_id, statement, option1, option2, option3, option4, default_option)
values ( (SELECT id FROM games WHERE game_name = '$game_name' limit 1), '$input_type', '$question', '$val1', '$val2', '$val3', '$val4', '$default_option')";
if(!mysql_query($sql)){
echo "Error";
}
else{
echo "Success";
}
//$error= mysql_error();
}
elseif($input_type=='2')
{
$question= $_POST['quest'];
$answer= $_POST['ans'];
// it is not implemented so leave it
}
}

upload a particular picture instead of submitting full form

I have a form name editdata.php. around 10 html controls(text box,file,select) using. I have a file control their picture of user is displaying and below this a file control is attached to change picture. I want that when a user browse and then change picture picture will automatically changed but form will not submit. so is this possible to upload picture without submitting the full form.
<html>
<head>
<meta charset="UTF-8">
<html lang="en">
<meta name="viewport" content="width=device-width, initial-scale=1"> <!--requuired for bootstrap -->
<link rel="stylesheet" href="Bootstrap/bootstrap.min.css" /> <!--bootstrap files -->
<script src="Bootstrap/jquery.min.js"></script>
<script src="Bootstrap/bootstrap.min.js"></script>
<style>
.error
{
color: red;
}
</style>
<title></title>
</head>
<body>
<div class="container">
<h1>Login Form</h1>
<h2><?php if(isset($_REQUEST['msg'])) echo $_REQUEST['msg'] ?></h2> <!-- Successful messgaeg if chnaged password -->
<form action="index.php" method="post" onsubmit="return checkData()" role="">
<div class="form-group">
<label>Username*</label>
<div><input type="text" class="form-control" id="uname" value="<?php if(isset($un)) echo $un; ?>" name="uname" onblur="setTimeout(function abc(){check_login_data('uname erruname blur', 'Username Must Be Entered')},130)" onfocus="check_login_data('uname erruname focus')" placeholder="Enter Username" /> <!-- textbox for username and checking value for cookie -->
</div>
</div>
<span class="error" id="erruname"> <?php if (isset($errorforusrnam)) echo $errorforusrnam; ?> </span> <!-- set a span for displaying error on emplty textbox -->
<div class="form-group">
<label>Password*</label>
<div><input type="password" class="form-control" id="password_id" name="upass" value="<?php if(isset($up)) echo ($up); ?>" placeholder="Enter Password" onblur="setTimeout(function abc(){check_login_data('password_id errpassword blur','Password Should Entered')},130)" onfocus="check_login_data('password_id errpassword focus')" /> <!-- textbox for Password and checking value for cookie -->
</div>
</div>
<span class="error" id="errpassword"> <?php if(isset($errorforpwd)) echo $errorforpwd ?> </span> <!-- set a span for displaying error on emplty textbox -->
<?php
if(isset($_SESSION['counter']) && $_SESSION['counter']>3) //captcha will show if user attempts more then 3
{
echo "<div class=form-group >"; //div for captcha
echo "<label for=captcha >Captcha*</label>";
echo "<div id=captcha_id>";
echo "<img id=imgCaptcha class=img-responsive src=captcha/create_image.php >";
echo '</div>';
echo '<div>';
echo "<div>";
echo "<input id=txtCaptcha class=form-control type=text name=txtCaptcha value='' placeholder='Enter Verification Code' />";
echo "<div><input class=btn btn-default type=button onclick=change_captcha() value=Reload /></div>";
echo "</div>";
echo "</div>";
echo "</div>"; //end of div
echo "<span class =error id=errco>"; //this will show error of div
if(isset($error))
{
echo $error;
}
echo '</span>';
}
?>
<div class="checkbox">
<label><input type="checkbox" name="chq" value="">Remember Me</label>
</div>
<div>
<input type="submit" name="sub" value="Login"class="btn btn-default" />
<a href="signup.php" />Signup</a>
<a href="forget_password.php" >Forgot Password</a>
</div>
<!-- <span id="span" ></span> span for showing output -->
</form>
</div>
</body>
</html>
and yeah all work will must have in single form...not is two forms. here I used two forms but I want to have a single form
GO through this liThis may Help You,
Ajax upload image on form showing thumbnail

Unable to show JQuery datepicker on my php page

I followed the source code on Jquery page to get a datepicker for my php page, but I cant get the calendar out. I think the Jquery is not loading for this page, can anyone tell me why? Thanks you
Here is my source code: I have my own designs for class element.
<html lang="en">
<head>
<meta charset="utf-8">
<title>Admin</title>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/navi.css" media="screen" />
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function(){
$(".box .h_title").not(this).next("ul").hide("normal");
$(".box .h_title").not(this).next("#home").show("normal");
$(".box").children(".h_title").click( function() { $(this).next("ul").slideToggle(); });
});
</script>
<script src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<script>
function validateForm()
{
var x=document.forms["my_form"]["title"].value;
var y=document.forms["my_form"]["author"].value;
var z=document.forms["my_form"]["keywords"].value;
var type=document.forms["my_form"]["category"].value;
if (x=="" || y=="" || z =="" || type=="")
{
alert("Please fill in the required fields");
return false;
}
}
</script>
<body>
<div class="wrap">
<div id="header">
<div id="top">
<div class="left">
<p>Welcome, <strong><?php echo $_SESSION['login']?> </strong> [ logout ]</p>
</div>
</div>
<div id="nav">
<ul>
<li class="upp">Manage Content
<ul>
<li>› Admin Home</li>
<li>› Manage Posts</li>
<li>› Manage User</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div id="sidebar">
<div class="box">
<div class="h_title">› Manage content</div>
<ul id="home">
<li class="b1"><a class="icon view_page" href="admin.php">Admin Home</a></li>
<li class="b2"><a class="icon report" href="viewPosts.php">Add Posts</a></li>
</ul>
</div>
<div class="box">
<div class="h_title">› Category</div>
<ul id="home">
<?php
include("includes/connect.php");
$sql = "SELECT post_type, COUNT(*) AS num FROM post WHERE post_status ='New' GROUP BY post_type";
$result = mysql_query($sql);
while($Cat_row= mysql_fetch_array($result)){
$type =$Cat_row['post_type'];
$number = $Cat_row['num'];
?>
<li class="b2"><a class="icon category" href="postType.php?cat=<?php echo $type?>"><?php echo $type." (".$number.")"?></a></li>
<?php }?>
</ul>
</div>
<div class="box">
<div class="h_title">› Archives</div>
<ul id="home">
<?php
include("includes/connect.php");
$sql_arc ="SELECT post_type, COUNT(*) AS numb FROM post WHERE post_status='Old' GROUP BY post_type";
$result_arc = mysql_query($sql_arc);
while($Arc_row= mysql_fetch_array($result_arc)){
$type_arc =$Arc_row['post_type'];
$number_arc = $Arc_row['numb'];
?>
<li class="b1"><a class="icon config" href="postArchive.php?type=<?php echo $type_arc?>"><?php echo $type_arc." (".$number_arc.")"?></a></li>
<?php }?>
</ul>
</div>
</div>
<div id="main">
<div class="full_w">
<div class="h_title">Add new Posts</div>
<form method="post" action="viewPosts.php" name="my_form" enctype="multipart/form-data" onsubmit="return validateForm()">
<div class="element">
<label >Title <span class="red">*</span></label>
<input type="text" name="title" class="text err" />
</div>
<div class="element">
<label>Author <span class="red">*</span></span></label>
<input type="text" name="author" class="text err" />
</div>
<div class="element">
<label>Keywords <span class="red">*</span></label>
<input type="text" name="keywords" class="text err" />
</div>
<div class="element">
<input type="text" id="datepicker">
</div>
<div class="element">
<label>Category <span class="red">*</span></label>
<select name="category" class="err">
<option value="">-- select category</option>
<option value="Class">Class</option>
<option value="Facilities">Facilities</option>
<option value="Services">Services</option>
<option value="Announcement">Announcement</option>
<option value="Promotions">Promotions</option>
<option value="News">News</option>
<option value="Uncategorized">Uncategorized</option>
</select>
</div>
<div class="element">
<label for="content">Page content <span>(required)</span></label>
<textarea id="editor1" name="content" class="textarea" rows="10"></textarea>
</div>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1',
{
// Load the German interface.
language: ''
});
</script>
<div class="entry">
<button type="submit" name="submit" class="add">Save Post</button>
<button class="cancel" type="reset" >Cancel</button>
</div>
</form>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<div class="left">
<p>NUS Staff Club Admin Panel</p>
</div>
</div>
</div>
</body>
</html>
<?php
include("includes/connect.php");
if(isset($_POST['submit'])){
$post_title = $_POST['title'];
$post_date = date("Y-m-d");
$post_author = $_POST['author'];
$post_keywords = $_POST['keywords'];
$post_type = $_POST['category'];
$post_content = $_POST['content'];
$post_status = 'New';
// $post_image = $_FILES['image']['name'];
// $image_temp = $_FILES['image']['tmp_name'];
/*if(empty($post_title) || empty($post_author) || empty($post_keywords) || empty($post_type) || empty($post_content) ){
exit();
}*/
// else{
// move_uploaded_file($image_temp,"../image/$post_image");
$insert_query = "insert into post (post_title,post_date,post_author,post_keywords,post_type,post_content,post_status) values ('$post_title','$post_date','$post_author'
,'$post_keywords','$post_type','$post_content','$post_status')";
if(mysql_query($insert_query)){
echo "<script>alert('Post has been pushlished successfully')</script>";
echo "<script>window.open('admin.php','_self')</script>";
}
else{ echo "<script>alert('failed')</script>";}
// }
}
?>
<?php }?>
You're calling your element before it's created...
replace
$(function() {
$( "#datepicker" ).datepicker();
});
by
$().ready(function() {
$( "#datepicker" ).datepicker();
})
;

Categories

Resources