Wordpress Plugin with shortcodes causes The White Screen Of Death - php

I wrote a plugin, which is working as intended. It adds a shortcode listener and outputs some HTML. The problem is when I re-login to wp-admin/, I only see the white screen of death. If I remove my plugin, Wordpress works just fine.
Here is the code:
<?php
/*
Plugin Name: Widgets
Plugin URI: http://dshatz.com
Description: A plugin for generating some website widgets
Version: 1.0
Author: Me
Author URI: http://dshatz.com
*/?>
<?php
function checkout_button_create(){
$ec = #$_GET['ec'];
$userId = #$_GET['id'];
$c = mysqli_connect("localhost", "user", "pwd", "db");
$stmt = $c->prepare("...");
$stmt->bind_param("is", $userId, $ec);
$stmt->execute();
$payment_id = $c->insert_id;
$stmt->close();
$stmt = $c->prepare("...");
$stmt->bind_param("i", $payment_id);
$stmt->execute();
$stmt->bind_result($name, $price);
$stmt->fetch();
$stmt->close();
$html = <<<EOD
<h1>$name</h1>
<form id="purchase_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value="..." />
<input name="item_name" type="hidden" value="..." />
<input name="currency_code" type="hidden" value="EUR" />
<input name="amount" type="hidden" value="$price" />
<input name="custom" type="hidden" value="$payment_id"></input>
<input name="lc" type="hidden" value="EN_US" />
<input name="no_note" type="hidden" value="" />
<input name="paymentaction" type="hidden" value="sale" />
<input name="return" type="hidden" value="/licenses/purchased/" />
<input name="bn" type="hidden" value="WPPlugin_SP" />
<input name="cancel_return" type="hidden" value="/" />
<input class="paypalbuttonimage" style="border: none;" alt="Make your payments with PayPal. It is free, secure, effective." name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" />
<img style="border: none; display: none;" src="http://i2.wp.com/www.paypal.com/EN_US/i/scr/pixel.gif?resize=1%2C1&ssl=1" alt="" width="1" height="1" border="0" /></form>
EOD;
return $html;
}
function register_form_create(){
$email = #$_GET['email'];
if(!isset($email)) $email="";
$ec = #$_GET['ec'];
$html = <<<EOD
<style>
input{
float: right;
}
form div{
padding-bottom: 10px;
}
.error_indicator{
color: red;
}
</style>
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
jQuery(document).ready(function(){
jQuery("form.register_form").submit(function(e){
var fieldsOk = true;
var mailOk = false;
var mail = jQuery("input[type='email']", jQuery(this));
mailOk = validateEmail(jQuery(mail).val());
jQuery("input", jQuery(this)).each(function(index){
if(jQuery(this).val().length == 0) {
fieldsOk = false;
return;
}
});
if(fieldsOk) jQuery(".fill_in_pls").css("display", "none");
else {
jQuery(".fill_in_pls").css("display", "inline");
jQuery(".invalid_email").css("display", "none");
e.preventDefault();
return false;
}
if(!mailOk){
e.preventDefault();
jQuery(".invalid_email", jQuery(this)).css("display", "inline");
return false;
}
jQuery(".invalid_email", jQuery(this)).css("display: none;");
return ;
});
});
</script>
<form class="register_form" method="POST" action="/license/register.php" style="width: 50%;">
<div>
<label for="email_input">Email</label><input id="email_input" type="email" name="email" value="$email"/>
</div>
<div>
<label for="fname_input">First name</label><input id="fname_input" type="text" name="fname"/>
</div>
<div>
<label for="lname_input">Last name</label><input id="lname_input" type="text" name="lname"/>
</div>
<input type="hidden" name="ec" value="$ec"/>
<div>
<input type="submit" value="Checkout"/>
</div>
<div class="error_indicator invalid_email" style="display: none;">Please enter a valid email</div>
<div class="error_indicator fill_in_pls" style="display: none;">Please fill in all fields</div>
</form>
EOD;
return $html;
}
add_shortcode('register', 'register_form_create');
add_shortcode('checkout', 'checkout_button_create');
?>
The code is running just perfect when I insert a shortcode on a page. What can cause this awful white screen?

Try this may be it works.
Just replace
var mail = jQuery("input[type='email']", jQuery(this));
TO
var mail = jQuery("input[type=\'email\']", jQuery(this));
I have added backslash.
Full plugin Code :
<?php
/**
* Plugin Name: Widgets
* Plugin URI: http://danielpataki.com
* Description: This plugin adds some Facebook Open Graph tags to our single posts.
* Version: 1.0.0
* Author: Daniel Pataki
* Author URI: http://danielpataki.com
* License: GPL2
*/
function checkout_button_create(){
$ec = #$_GET['ec'];
$userId = #$_GET['id'];
$c = mysqli_connect("localhost", "user", "pwd", "db");
$stmt = $c->prepare("...");
$stmt->bind_param("is", $userId, $ec);
$stmt->execute();
$payment_id = $c->insert_id;
$stmt->close();
$stmt = $c->prepare("...");
$stmt->bind_param("i", $payment_id);
$stmt->execute();
$stmt->bind_result($name, $price);
$stmt->fetch();
$stmt->close();
$html = '<h1>$name</h1>
<form id="purchase_form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"><input name="cmd" type="hidden" value="_xclick" />
<input name="business" type="hidden" value="..." />
<input name="item_name" type="hidden" value="..." />
<input name="currency_code" type="hidden" value="EUR" />
<input name="amount" type="hidden" value="$price" />
<input name="custom" type="hidden" value="$payment_id"></input>
<input name="lc" type="hidden" value="EN_US" />
<input name="no_note" type="hidden" value="" />
<input name="paymentaction" type="hidden" value="sale" />
<input name="return" type="hidden" value="/licenses/purchased/" />
<input name="bn" type="hidden" value="WPPlugin_SP" />
<input name="cancel_return" type="hidden" value="/" />
<input class="paypalbuttonimage" style="border: none;" alt="Make your payments with PayPal. It is free, secure, effective." name="submit" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" type="image" />
<img style="border: none; display: none;" src="http://i2.wp.com/www.paypal.com/EN_US/i/scr/pixel.gif?resize=1%2C1&ssl=1" alt="" width="1" height="1" border="0" /></form>';
return $html;
}
function register_form_create(){
$email = #$_GET['email'];
if(!isset($email)) $email="";
$ec = #$_GET['ec'];
$html = '<style>
input{
float: right;
}
form div{
padding-bottom: 10px;
}
.error_indicator{
color: red;
}
</style>
<script type="text/javascript">
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
jQuery(document).ready(function(){
jQuery("form.register_form").submit(function(e){
var fieldsOk = true;
var mailOk = false;
var mail = jQuery("input[type=\'email\']", jQuery(this));
mailOk = validateEmail(jQuery(mail).val());
jQuery("input", jQuery(this)).each(function(index){
if(jQuery(this).val().length == 0) {
fieldsOk = false;
return;
}
});
if(fieldsOk) jQuery(".fill_in_pls").css("display", "none");
else {
jQuery(".fill_in_pls").css("display", "inline");
jQuery(".invalid_email").css("display", "none");
e.preventDefault();
return false;
}
if(!mailOk){
e.preventDefault();
jQuery(".invalid_email", jQuery(this)).css("display", "inline");
return false;
}
jQuery(".invalid_email", jQuery(this)).css("display: none;");
return ;
});
});
</script>
<form class="register_form" method="POST" action="/license/register.php" style="width: 50%;">
<div>
<label for="email_input">Email</label><input id="email_input" type="email" name="email" value="$email"/>
</div>
<div>
<label for="fname_input">First name</label><input id="fname_input" type="text" name="fname"/>
</div>
<div>
<label for="lname_input">Last name</label><input id="lname_input" type="text" name="lname"/>
</div>
<input type="hidden" name="ec" value="$ec"/>
<div>
<input type="submit" value="Checkout"/>
</div>
<div class="error_indicator invalid_email" style="display: none;">Please enter a valid email</div>
<div class="error_indicator fill_in_pls" style="display: none;">Please fill in all fields</div>
</form>';
return $html;
}
add_shortcode('register', 'register_form_create');
add_shortcode('checkout', 'checkout_button_create');
?>

Related

How to pass value of a input to other input in paypal button

I have a paypal button and I need to get some information when it is clicked:
Name and name of post.
I have this input field for the name.
<span class="intestazione-form">Name*</span><br>
<input type="text" id="searchTxt" name="name" value="" size="40" class=" nome-input" placeholder="Insert your name">
Then the paypal button.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="item_name" value="<?php echo the_title(); ?> ">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="xxxxxx" />
<input id="btnSubmit" class="btn" type="submit" value="DONA CON PAYPAL" type="image" border="0" name="submit" title="PayPal - The safer, easier way to pay online!" alt="Donate with PayPal button" disabled/>
img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />
</form>
This works, item_name get title of post and I see it in details of paypal transiction.
How pass the name in value of item_name with the_title(); ???
ok, I solved. In your script I add this:
function submitForm(){
var nome_post = 'CAMPAGNA: <?php echo the_title(); ?> NOME DONATORE: ' ;
var name = document.getElementById('searchTxt').value;
var res = nome_post.concat(name);
document.getElementById('item_name').value = res;
if(name) return true;
else return false;
return true;
}
You can use onsubmit in your form tag, just like below
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onsubmit="return submitForm();" >
Using the function submitForm you can fill the element item_name
<script type="text/javascript">
function submitForm(){
var name = document.getElementById('searchTxt').value;
document.getElementById('item_name').value = name;
if(name)
return true;
else
return false;
return true;
}
</script>
Full Code for understanding
<span class="intestazione-form">Name*</span><br>
<input type="text" id="searchTxt" name="name" value="" size="40" class=" nome-input" placeholder="Insert your name">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" onsubmit="return submitForm();" >
<input type="hidden" name="item_name" id="item_name" value="<?php //echo the_title(); ?> ">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="xxxxxx" />
<input id="btnSubmit" class="btn" type="submit" value="DONA CON PAYPAL" />
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" />
</form>
<script type="text/javascript">
function submitForm(){
var name = document.getElementById('searchTxt').value;
document.getElementById('item_name').value = name;
if(name)
return true;
else
return false;
return true;
}
</script>
You can create one more hidden field like
<inout type="hidden" name="field_name" id="field_name" />
after that javascript
document.getElementById('field_name').value = name;

Comment the same again and again

I am trying to make a comments section, where people can comment stuff on my webpage.
All the comments get to a database. Alle that works fine.
The only problem I have is, when i have commented some stuff and reload the webpage it comment the same thing again.
Is there a if statement or something to prevent this?
while ($info = mysql_fetch_array($result)){
echo '<div style="border-style: solid; border-color: #808080; border-width: thin">
<div style="width: 1%"><p style="font-size: 10px; margin: 0px">'.$info['Navn'].'</p></div>
<p>'.$info['Besked'].'</p>
</div>';
}
if (isset($_POST['navn']) && isset($_POST['besked']) && isset($_POST['submit'])) {
$navn2 = $_POST['navn'];
$besked2 = $_POST['besked'];
$data = "INSERT INTO `tester`.`davs` (`Navn`, `Besked`) VALUES ('$navn2', '$besked2');";
$resultalt = mysql_query($data);
if ($resultalt) {
echo "$resultat";
}else{
echo "$resultat";
}
mysql_close();
}
?>
<form action="database.php" method="post" id="commentform">
<label for="comment_author" class="required">Your name</label>
<input type="text" name="navn" id="comment_author" value="" tabindex="1" required="required">
<label for="comment" class="required">Your message</label>
<textarea name="besked" id="comment" rows="10" tabindex="4" required="required"></textarea>
<input type="hidden" name="comment_post_ID" value="1" id="comment_post_ID" />
<input name="submit" type="submit" value="Submit comment" />
</form>
my php code:
http://pastebin.com/bQ7c1MPD
my inputs:
http://pastebin.com/P9uc6Hhz
Use tokens in your HTML form:
<input type="hidden" name="token" value="<?=$_SESSION['token'] = uniqid(); ?>" />
This require this at the top of the PHP script (before any output):
session_start();
For validation:
if(isset($_POST['submit']) && $_POST['token'] == $_SESSION['token']))
Full code: PHP | Form

PHP $_POST returns null values

This is my html code:
<form style="width: 20%; margin: auto;" action="subscribe.php" method="post" id="subscribeToNews">
<fieldset>
<legend>Subscribe:</legend>
<label for="subName">First Name:</label><br /><input type="text" id="subName" name="subName" /><br />
<label for="subEmail">Email:</label><br /><input type="text" id="subEmail" name="subEmail" /><br />
<input style="width: inherit;" type="submit" value="Subscribe" />
</fieldset>
</form>
This is the subscribe.php file:
<?php
$con = mysqli_connect('95.76.197.98','root','','accounts');
print_r($_POST);
if (isset($_POST["subName"]) && isset($_POST["subEmail"])){
$subUser = $_POST["subName"];
$subEmail = $_POST["subEmail"];
echo "$subUser"."<br />"."$subEmail";
}
?>
I have really tried a lot of things out there on the Internet and nothing seems to work for me. Any ideas?
Also looks like the get method works for this...
Could by related to your nginx configuration.
Try:
$post = file_get_contents("php://input");
This should work:
<form style="width: 20%; margin: auto;" action="subscribe.php" method="post" id="subscribeToNews">
<fieldset>
<legend>Subscribe:</legend>
<label for="subName">First Name:</label><br /><input type="text" id="subName" name="subName" /><br />
<label for="subEmail">Email:</label><br /><input type="text" id="subEmail" name="subEmail" /><br />
<input style="width: inherit;" type="submit" value="Subscribe" />
</fieldset>
</form>
<?php
$con = mysqli_connect('95.76.197.98','root','','accounts');
if($_POST) {
$subName = mysqli_real_escape_string($con, strip_tags($_POST['subName']));
$subEmail = mysqli_real_escape_string($con, strip_tags($_POST['subEmail']));
if(isset($subName) && !empty($subName) && isset($subEmail) && !empty($subMail)) {
echo 'Name: '.$subName.'<br> Email: '.$subEmail;
}
}
?>

Textarea-N with recount and disable button function

JS
$(document).ready(function(){
$('.comment').bind("blur focus keydown keypress keyup", function(){recountss();});
$('input.comment_button').attr('disabled','disabled');
$('#form').submit(function(e){
tweet();
});
});
function recountss()
{
var maxlen=280;
var current = maxlen-$('.comment').val().length;
$('.counters').html(current);
if(current<0 || current==maxlen)
{
$('.counters').css('color','#D40D12');
$('input.comment_button').attr('disabled','disabled').addClass('inact');
}
else if (!$.trim($(".comment").val()))
{
$('input.comment_button').attr('disabled','disabled').addClass('inact');
}
else
$('input.comment_button').removeAttr('disabled').removeClass('inact');
if(current<10)
{
$('.counters').css('color','#D40D12');
}
else if(current<20)
{
$('.counters').css('color','#5C0002');
}
else
{
$('.counters').css('color','#C0C0C0');
}
HTML
<form method="post" action="" id="form">
<textarea name="comment" class="comment" id="ctextarea<?php echo $msg_id;?>" ></textarea>
<input type="hidden" name="uid" id="uid" value="<?php echo $uid; ?>"/>
<div class="p"></div>
<input type="submit" value="Comment" id="<?php echo $msg_id;?>" class="comment_button"/>
<span class="counters">
280
</span>
</form>
I using jquery.
I have more than 1 textarea, if I type in textarea-1, it work, button disabled if no any text and recount working good.
But if I type in textarea-2, textarea-3, textarea-N, it can't work.
So how can I do to make all works ?
Thank you.
If each <textarea> has its own maxlen=280, it would be better to change from using class - $('.comment') to id - $('#ctextarea-'+i) on all elements - <textarea>, <button>, <span>, etc.
This is untested, but should help point you in the right direction.
$(document).ready(function(){
var i=1;
var numtextarea = 1;
$('#form').find('textarea').each(function(){numtextarea++;} //find number of <textarea>'s
while(i<numtextarea){ // loop through each <textarea>
$('#ctextarea-'+i).bind("blur focus keydown keypress keyup", function(){recountss(i);});
$('#comment_button-'i).attr('disabled','disabled');
}
});
$('#form').submit(function(e){
tweet();
});
});
function recountss(i)
{
var maxlen=280;
var current = maxlen-$('#ctextarea-'+i).val().length;
$('#counters-'+i).html(current);
if(current<0 || current==maxlen)
{
$('#counters-'+i).css('color','#D40D12');
$('#comment_button-'+i).attr('disabled','disabled').addClass('inact');
}
else if (!$.trim($("#ctextarea-'+i).val())) {
$('#comment_button-'+i).attr('disabled','disabled').addClass('inact');
}
else
$('#comment_button-'+i).removeAttr('disabled').removeClass('inact');
if(current<10)
$('#counters-'+i).css('color','#D40D12');
else if(current<20)
$('#counters-'+i).css('color','#5C0002');
else
$('#counters-'+i).css('color','#C0C0C0');
}
And your form should look like -
<form method="post" action="" id="form">
<textarea name="comment" class="comment" id="ctextarea-1" ></textarea>
<input type="hidden" name="uid" id="uid" value="1"/>
<div class="p"></div>
<input type="submit" value="Comment" id="comment_button-1" class="comment_button"/>
<span id="counters-1">
280
</span>
<textarea name="comment" class="comment" id="ctextarea-2" ></textarea>
<input type="hidden" name="uid" id="uid" value="2"/>
<div class="p"></div>
<input type="submit" value="Comment" id="comment_button-2" class="comment_button"/>
<span id="counters-2">
280
</span>
...
<textarea name="comment" class="comment" id="ctextarea-N" ></textarea>
<input type="hidden" name="uid" id="uid" value="N"/>
<div class="p"></div>
<input type="submit" value="Comment" id="comment_button-N" class="comment_button"/>
<span id="counters-N">
280
</span>
</form>

Form captcha without refreshing page

Hello i have the following code, it works i mean it validates captcha good but it doesnt POST values in the sign_form.php
<script>
$(document).ready(function() {
$('#Send').click(function() {
$.post("sign_form.php?"+$("#sign_form").serialize(), {
}, function(response){
if(response==1)
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Your message has been submitted.</div>');
change_captcha();
clear_form();
}
else
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Error ! invalid captcha code .</div>');
}
});
return false;
});
// refresh captcha
$('img#refresh').click(function() {
change_captcha();
});
function change_captcha()
{
document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
function clear_form()
{
$("#name").val('');
$("#email").val('');
$("#message").val('');
}
});
form code
<form id="sign_form" name="sign_form" method="POST" action="#">
<fieldset class="step">
<legend>Podepsat tuto petici</legend>
<p>
<label for="first_name">Křestní jméno:</label>
<input type="text" name="first_name" id="first_name">
</p>
<p>
<label for="last_name">Příjmení:</label>
<input type="text" name="last_name" id="last_name">
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="email">Mesto:</label>
<input type="text" name="city" id="city">
</p>
<p>
<div id="wrap" align="center">
<img src="get_captcha.php" alt="" id="captcha" />
<br clear="all" />
<input name="code" type="text" id="code">
</div>
<img src="refresh.jpg" width="25" alt="" id="refresh" />
</p>
<p>
<input type="hidden" value="'.$id.'" name="id" id="id">
</p>
<p>
Emailová adresa nebude zveřejněna a nebude <br>předána žádné třetí straně.
</p>
<p>
<button type="submit" value="send" id="Send"></button>
<div id="status"></div>
</p>
</form>
sign_form.php code
session_start();
require_once('engine/db.php');
mysql_query("SET NAMES utf8");
if(($_REQUEST['code'] == $_SESSION['random_number']) || #strtolower($_REQUEST['code']) == strtolower($_SESSION['random_number']) )
{
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$city=$_POST['city'];
$id=$_POST['id'];
$insert = "INSERT INTO petition_vote
(id_petition,first_name,last_name,email,city)
VALUES ('".$id."','".mysql_real_escape_string($first_name)."','".mysql_real_escape_string($last_name)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($city)."')";
//$add_member = mysql_query($insert);
$result = mysql_query($insert)
or die("query failed: " . mysql_error());
echo 1;
}
else
{
echo 0;
}
I came with an update to the code but then it refreshes my page
if(response==1)
{
submitform();
}
else
…
function submitform()
{
document.forms.sign_form.submit();
}
Replace your index.php to
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function() {
$('#Send').click(function() {
serializedData=$("#MYFORM").serialize();
$.ajax({
url: "post.php",
type: "post",
data: serializedData,
// callback handler that will be called on success
success: function(response){
alert(response);
if(response==1)
{
$("#after_submit").html('');
$("#Send").after('<label class="success" id="after_submit">Your message has been submitted.</label>');
change_captcha();
clear_form();
}
else
{
$("#after_submit").html('');
$("#Send").after('<label class="error" id="after_submit">Error ! invalid captcha code .</label>');
}
}
});
return false;
});
// refresh captcha
$('img#refresh').click(function() {
change_captcha();
});
function change_captcha()
{
document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
function clear_form()
{
$("#name").val('');
$("#email").val('');
$("#message").val('');
}
});
</script>
<style>
body{ font-family:Georgia, "Times New Roman", Times, serif; font-size:14px}
#wrap{
border:solid #CCCCCC 1px;
width:203px;
-webkit-border-radius: 10px;
float:left;
-moz-border-radius: 10px;
border-radius: 10px;
padding:3px;
margin-top:3px;
margin-left:80px;
}
.error{ color:#CC0000; font-size:12px; margin:4px; font-style:italic; width:200px;}
.success{ color:#009900; font-size:12px; margin:4px; font-style:italic; width:200px;}
img#refresh{
float:left;
margin-top:30px;
margin-left:4px;
cursor:pointer;
}
#name,#email{float:left;margin-bottom:3px; height:20px; border:#CCCCCC 1px solid;}
#message{ width:260px; height:100px;float:left;margin-bottom:3px; border:#CCCCCC 1px solid;}
label{ float:left; color:#666666; width:80px;}
#Send{ border:#CC0000 solid 1px; float:left; background:#CC0000; color:#FFFFFF; padding:5px;}
</style>
</head>
<body>
<br clear="all" />
<br clear="all" />
<br clear="all" />
<div align="left" style="padding:30px;">
<form action="#" name="MYFORM" id="MYFORM">
<label>Name</label>
<input name="name" size="30" type="text" id="name">
<br clear="all" />
<label>Email</label>
<input name="email" size="30" type="text" id="email">
<br clear="all" />
<label>Message</label>
<textarea id="message" name="message"></textarea>
<br clear="all" />
<div id="wrap" align="center">
<img src="get_captcha.php" alt="" id="captcha" />
<br clear="all" />
<input name="code" type="text" id="code">
</div>
<img src="refresh.jpg" width="25" alt="" id="refresh" />
<br clear="all" /><br clear="all" />
<label> </label>
<input value="Send" type="submit" id="Send">
</form>
</div>
<br clear="all" /><br clear="all" /><br clear="all" /><br clear="all" />
<br clear="all" /><br clear="all" /><br clear="all" /><br clear="all" />
<br clear="all" /><br clear="all" />
</body>
</html>
and post.php as
<?php
session_start();
//print_r($_SESSION);
if(($_REQUEST['code'] == $_SESSION['random_number']) || #strtolower($_REQUEST['code']) == strtolower($_SESSION['random_number']) )
{
//$email=$_REQUEST['email'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$city=$_POST['city'];
$id=$_POST['id'];
echo $insert = "INSERT INTO petition_vote
(id_petition,first_name,last_name,email,city)
VALUES ('".$id."','".mysql_real_escape_string($first_name)."','".mysql_real_escape_string($last_name)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($city)."')";
//$add_member = mysql_query($insert);
$result = mysql_query($insert)or die("query failed: " . mysql_error());
echo 1;
echo 1;// submitted
//echo''.$email.'';
}
else
{
echo 0; // invalid code
}
?>
I have tested it as:
form page as:
<?php
session_start();
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
$('#Send').click(function() {
$.post("sign_form.php?"+$("#sign_form").serialize(), {
}, function(response){
alert(response);
if(response==1)
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Your message has been submitted.</div>');
change_captcha();
clear_form();
}
else
{
$("#after_submit").html('');
$("#Send").after('<div id="after_submit">Error ! invalid captcha code .</div>');
}
});
return false;
});
// refresh captcha
$('img#refresh').click(function() {
change_captcha();
});
function change_captcha()
{
document.getElementById('captcha').src="get_captcha.php?rnd=" + Math.random();
}
function clear_form()
{
$("#name").val('');
$("#email").val('');
$("#message").val('');
}
});
</script>
<form id="sign_form" name="sign_form" method="POST" action="#">
<fieldset class="step">
<legend>Podepsat tuto petici</legend>
<p>
<label for="first_name">K?estní jméno:</label>
<input type="text" name="first_name" id="first_name">
</p>
<p>
<label for="last_name">P?íjmení:</label>
<input type="text" name="last_name" id="last_name">
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="email">Mesto:</label>
<input type="text" name="city" id="city">
</p>
<p>
<div id="wrap" align="center">
<img src="get_captcha.php" alt="" id="captcha" />
<br clear="all" />
<input name="code" type="text" id="code">
</div>
<img src="refresh.jpg" width="25" alt="" id="refresh" />
</p>
<p>
<input type="hidden" value="'.$id.'" name="id" id="id">
</p>
<p>
Emailová adresa nebude zve?ejn?na a nebude <br>p?edána žádné t?etí stran?.
</p>
<p>
<button type="submit" value="send" id="Send"></button>
<div id="status"></div>
</p>
</form>
php page sign_form.php
<?php
session_start();
//require_once('engine/db.php');
//mysql_query("SET NAMES utf8");
echo print_r($_REQUEST);
if(($_REQUEST['code'] == $_SESSION['random_number']) || #strtolower($_REQUEST['code']) == strtolower($_SESSION['random_number']) )
{
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$city=$_POST['city'];
$id=$_POST['id'];
$insert = "INSERT INTO petition_vote
(id_petition,first_name,last_name,email,city)
VALUES ('".$id."','".mysql_real_escape_string($first_name)."','".mysql_real_escape_string($last_name)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($city)."')";
//$add_member = mysql_query($insert);
$result = mysql_query($insert)
or die("query failed: " . mysql_error());
echo 1;
}
else
{
echo 0;
}
?>
On submit it is alerting all the values.then what is your problem?

Categories