Autor Zpráva
gully
Profil
Ahoj všem,

chtěl bych pomoct s bílou stránkou, která mi zůstává viset po odeslání formuláře na této stránce. Bílá stránka ex2_result.php obsahuje tento kód:

<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8" />
<title>Vaše objednávka</title>
<link rel="stylesheet" href="includes/order_form.css" type="text/css" />
</head>
<body>
<?php
require_once('includes/ex2.inc.php');
echo handleOrderInfo();
?>
    
    
<p>&nbsp;</p>
<p>A <code>sendAdminEmail</code> function is included in ex2.inc.php. You will need to place your email address there (<code>$admin_email</code>) and uncomment the <code>mail</code> function to send the emails.</p>

<p>Back to <a href=".">index</a></p>

</body>
</html>

Soubor ex2.inc.php:
<?php
/* 
    Example php order form created using form and table classes from dyn-web.com
    For demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    Released under the MIT license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "SELECT id, nazev, cena_mj FROM vyrobky WHERE zobrazovat = 'Ano' ORDER BY nazev";
    $mysqlidb = new mySQLiDB;
    $result = $mysqlidb->runQuery($query);

    while($row = $result->fetch_array())
    {
       $PRODUCTS[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getOrderForm2() {
    global $PRODUCTS;
    $tbl = new HTML_Table('', 'demoTbl');
    $frm = new HTML_Form();
    
    // header row
    $tbl->addRow();
        $tbl->addCell('Druh', 'first', 'header');
        $tbl->addCell('Cena/jedn.', '', 'header');
        $tbl->addCell('Množství', '', 'header');
        $tbl->addCell('Celkem', '', 'header');
    
    // display product info/form elements
    foreach($PRODUCTS as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addInput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getProductTotal(this)',
                  'onclick'=>'checkValue(this)', 'onblur'=>'reCheckValue(this)') );
        
        // total text input
        $tot_el = $frm->addInput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addInput('hidden', $abbr . '_price', $price);
        
        $tbl->addRow();
            $tbl->addCell($name);
            $tbl->addCell(number_format($price, 2). ' Kč' . $price_el, 'cur' );
            $tbl->addCell( $qty_el, 'qty');
            $tbl->addCell( $tot_el );
    }
    
    // total row
    $tbl->addRow();
        $tbl->addCell( 'Celkem (Kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addCell( $frm->addInput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addRow();
        $tbl->addCell('Jméno: ', 'label');
        $tbl->addCell(
            $frm->addInput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addRow();
        $tbl->addCell('Příjmení: ', 'label');
        $tbl->addCell(
            $frm->addInput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addRow();
        $tbl->addCell('Email: ', 'label');
        $tbl->addCell(
            $frm->addInput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-zA-Z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addRow();
        $tbl->addCell('Mobil: ', 'label');
        $tbl->addCell(
            $frm->addInput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addRow();
        $tbl->addCell('Komentář: ', 'label');
        $tbl->addCell(
            $frm->addTextArea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[Komentář k objednávce]') )
        );

    // submit button
    $tbl->addRow();
        $tbl->addCell( $frm->addInput('submit', 'submit', 'Odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__DIR__);    
    $frmStr = $frm->startForm('ex2_result.php', 'post', '', array('onsubmit'=>'return checkSubmit(this);') ) .
        $tbl->display() . $frm->endForm();
    
    
    return $frmStr;
}


// for js
function getProductAbbrs() {
    global $PRODUCTS;
    foreach ( $PRODUCTS as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendAdminEmail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'Nova objednavka';
    $name = stripslashes( strip_tags( $_POST['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_POST['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_POST['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-zA-Z]{2,}$/';
    if ( !preg_match($regex, $_POST['email']) ) {
        // don't send email
        echo '<p>Zadaná e-mailová je neplatná. Klepnutím na tlačítko Zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_POST['phone'] ) );
    $msg_body = "Objednávka pro: 
    $order 
    
    Celkem: $$total
    
    Jméno: $name
    Email: $email
    Mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleOrderInfo() {
    global $PRODUCTS;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_POST) ) {
        // Check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($PRODUCTS as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>Je nám líto, ale tuto Vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>Vaše objednávka:</h2>$str<p>Celkem: $$total</p>";
        sendAdminEmail($total, $order);
    }
    
    return $str;
}
?>

<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__dir__);    
    $frmstr = $frm->startform('ex2_result.php', 'post', '', array('onsubmit'=>'return checksubmit(this);') ) .
        $tbl->display() . $frm->endform();
    
    
    return $frmstr;
}


// for js
function getproductabbrs() {
    global $products;
    foreach ( $products as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendadminemail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'nova objednavka';
    $name = stripslashes( strip_tags( $_post['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_post['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_post['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$/';
    if ( !preg_match($regex, $_post['email']) ) {
        // don't send email
        echo '<p>zadaná e-mailová je neplatná. klepnutím na tlačítko zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_post['phone'] ) );
    $msg_body = "objednávka pro: 
    $order 
    
    celkem: $$total
    
    jméno: $name
    email: $email
    mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleorderinfo() {
    global $products;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_post) ) {
        // check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($products as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>je nám líto, ale tuto vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>vaše objednávka:</h2>$str<p>celkem: $$total</p>";
        sendadminemail($total, $order);
    }
    
    return $str;
}
?>

soubor ex2.inc.php:
<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__dir__);    
    $frmstr = $frm->startform('ex2_result.php', 'post', '', array('onsubmit'=>'return checksubmit(this);') ) .
        $tbl->display() . $frm->endform();
    
    
    return $frmstr;
}


// for js
function getproductabbrs() {
    global $products;
    foreach ( $products as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendadminemail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'nova objednavka';
    $name = stripslashes( strip_tags( $_post['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_post['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_post['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$/';
    if ( !preg_match($regex, $_post['email']) ) {
        // don't send email
        echo '<p>zadaná e-mailová je neplatná. klepnutím na tlačítko zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_post['phone'] ) );
    $msg_body = "objednávka pro: 
    $order 
    
    celkem: $$total
    
    jméno: $name
    email: $email
    mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleorderinfo() {
    global $products;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_post) ) {
        // check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($products as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>je nám líto, ale tuto vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>vaše objednávka:</h2>$str<p>celkem: $$total</p>";
        sendadminemail($total, $order);
    }
    
    return $str;
}
?>


<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8" />
<title>vaše objednávka</title>
<link rel="stylesheet" href="includes/order_form.css" type="text/css" />
</head>
<body>
<?php
require_once('includes/ex2.inc.php');
echo handleorderinfo();
?>
    
    
<p>&nbsp;</p>
<p>a <code>sendadminemail</code> function is included in ex2.inc.php. you will need to place your email address there (<code>$admin_email</code>) and uncomment the <code>mail</code> function to send the emails.</p>

<p>back to <a href=".">index</a></p>

</body>
</html>

soubor ex2.inc.php:
<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__dir__);    
    $frmstr = $frm->startform('ex2_result.php', 'post', '', array('onsubmit'=>'return checksubmit(this);') ) .
        $tbl->display() . $frm->endform();
    
    
    return $frmstr;
}


// for js
function getproductabbrs() {
    global $products;
    foreach ( $products as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendadminemail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'nova objednavka';
    $name = stripslashes( strip_tags( $_post['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_post['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_post['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$/';
    if ( !preg_match($regex, $_post['email']) ) {
        // don't send email
        echo '<p>zadaná e-mailová je neplatná. klepnutím na tlačítko zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_post['phone'] ) );
    $msg_body = "objednávka pro: 
    $order 
    
    celkem: $$total
    
    jméno: $name
    email: $email
    mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleorderinfo() {
    global $products;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_post) ) {
        // check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($products as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>je nám líto, ale tuto vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>vaše objednávka:</h2>$str<p>celkem: $$total</p>";
        sendadminemail($total, $order);
    }
    
    return $str;
}
?>


<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8" />
<title>vaše objednávka</title>
<link rel="stylesheet" href="includes/order_form.css" type="text/css" />
</head>
<body>
<?php
require_once('includes/ex2.inc.php');
echo handleorderinfo();
?>
    
    
<p>&nbsp;</p>
<p>a <code>sendadminemail</code> function is included in ex2.inc.php. you will need to place your email address there (<code>$admin_email</code>) and uncomment the <code>mail</code> function to send the emails.</p>

<p>back to <a href=".">index</a></p>

</body>
</html>

soubor ex2.inc.php:
<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__dir__);    
    $frmstr = $frm->startform('ex2_result.php', 'post', '', array('onsubmit'=>'return checksubmit(this);') ) .
        $tbl->display() . $frm->endform();
    
    
    return $frmstr;
}


// for js
function getproductabbrs() {
    global $products;
    foreach ( $products as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendadminemail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'nova objednavka';
    $name = stripslashes( strip_tags( $_post['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_post['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_post['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$/';
    if ( !preg_match($regex, $_post['email']) ) {
        // don't send email
        echo '<p>zadaná e-mailová je neplatná. klepnutím na tlačítko zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_post['phone'] ) );
    $msg_body = "objednávka pro: 
    $order 
    
    celkem: $$total
    
    jméno: $name
    email: $email
    mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleorderinfo() {
    global $products;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_post) ) {
        // check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($products as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>je nám líto, ale tuto vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>vaše objednávka:</h2>$str<p>celkem: $$total</p>";
        sendadminemail($total, $order);
    }
    
    return $str;
}
?>


chtěl bych pomoct s bílou stránkou, která mi zůstává viset po odeslání formuláře na této stránce. bílá stránka ex2_result.php obsahuje tento kód:

<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8" />
<title>vaše objednávka</title>
<link rel="stylesheet" href="includes/order_form.css" type="text/css" />
</head>
<body>
<?php
require_once('includes/ex2.inc.php');
echo handleorderinfo();
?>
    
    
<p>&nbsp;</p>
<p>a <code>sendadminemail</code> function is included in ex2.inc.php. you will need to place your email address there (<code>$admin_email</code>) and uncomment the <code>mail</code> function to send the emails.</p>

<p>back to <a href=".">index</a></p>

</body>
</html>

soubor ex2.inc.php:
<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array('colspan'=>4) );
    chdir(__dir__);    
    $frmstr = $frm->startform('ex2_result.php', 'post', '', array('onsubmit'=>'return checksubmit(this);') ) .
        $tbl->display() . $frm->endform();
    
    
    return $frmstr;
}


// for js
function getproductabbrs() {
    global $products;
    foreach ( $products as $product ) {
        $ar[] = $product[0];
    }
    return $ar;
}


// functions for example 2 order form submission result page

function sendadminemail($total, $order) {
    $admin_email = 'xxxxxxx@gmail.com';
    $subject = 'nova objednavka';
    $name = stripslashes( strip_tags( $_post['first_name'] ) ) . ' ' . 
        stripslashes( strip_tags( $_post['last_name'] ) );
    
    $email = stripslashes( strip_tags( $_post['email'] ) );
    // check for valid email address
    $regex = '/^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$/';
    if ( !preg_match($regex, $_post['email']) ) {
        // don't send email
        echo '<p>zadaná e-mailová je neplatná. klepnutím na tlačítko zpět se vráťte na předchozí stránku a zadejte platnou e-mailovou adresu.</p>';
        return;
    }
    $phone = stripslashes( strip_tags( $_post['phone'] ) );
    $msg_body = "objednávka pro: 
    $order 
    
    celkem: $$total
    
    jméno: $name
    email: $email
    mobil: $phone";
    
    //echo nl2br($msg_body); // for testing
    
    @mail($admin_email, $subject, $msg_body );
}


function handleorderinfo() {
    global $products;;
    $str = ''; $total = 0; $order = '';
    while ( list($key, $val) = each($_post) ) {
        // check for valid quantity entries
        if ( ( strpos($key, '_qty') !== false ) && is_int((int)$val) && $val > 0  ) { 
            $pt = strrpos($key, '_qty'); // get product abbr
            $name_pt = substr( $key, 0, $pt);
            
            foreach($products as $product) {
                list($prod_abbr, $prod_name, $prod_price) = $product;
                if ($prod_abbr == $name_pt) {
                    $sub_tot = $val * $prod_price;
                    // build string to display order info
                    $str .= "<p>$val $prod_name at $" . number_format($prod_price, 2) . 
                        ' each for $' . number_format($sub_tot, 2) . '</p>';
                    $total += $sub_tot;
                    $order .= "$val $prod_abbr, ";
                }
            }
        }
    }
    $total = number_format($total, 2);
    $order = rtrim($order, ', ');
    if ( $str === '' ) {
        $str = '<p>je nám líto, ale tuto vaši objednávku nemůžeme akceptovat, protože jste si nic neobjednali.</p>';
    } else {
        $str = "<h2>vaše objednávka:</h2>$str<p>celkem: $$total</p>";
        sendadminemail($total, $order);
    }
    
    return $str;
}
?>


chtěl bych pomoct s bílou stránkou, která mi zůstává viset po odeslání formuláře na této stránce. bílá stránka ex2_result.php obsahuje tento kód:

<!doctype html>
<html lang="cs">
<head>
<meta charset="utf-8" />
<title>vaše objednávka</title>
<link rel="stylesheet" href="includes/order_form.css" type="text/css" />
</head>
<body>
<?php
require_once('includes/ex2.inc.php');
echo handleorderinfo();
?>
    
    
<p>&nbsp;</p>
<p>a <code>sendadminemail</code> function is included in ex2.inc.php. you will need to place your email address there (<code>$admin_email</code>) and uncomment the <code>mail</code> function to send the emails.</p>

<p>back to <a href=".">index</a></p>

</body>
</html>

soubor ex2.inc.php:
<?php
/* 
    example php order form created using form and table classes from dyn-web.com
    for demos, documentation and updates, visit http://www.dyn-web.com/code/order_form/
    
    released under the mit license
    http://www.dyn-web.com/business/license.txt
*/
    $query = "select id, nazev, cena_mj from vyrobky where zobrazovat = 'ano' order by nazev";
    $mysqlidb = new mysqlidb;
    $result = $mysqlidb->runquery($query);

    while($row = $result->fetch_array())
    {
       $products[] = $row; //
    }
    $result->close();

// functions for example 2 order form

function getorderform2() {
    global $products;
    $tbl = new html_table('', 'demotbl');
    $frm = new html_form();
    
    // header row
    $tbl->addrow();
        $tbl->addcell('druh', 'first', 'header');
        $tbl->addcell('cena/jedn.', '', 'header');
        $tbl->addcell('množství', '', 'header');
        $tbl->addcell('celkem', '', 'header');
    
    // display product info/form elements
    foreach($products as $product) {
        list($abbr, $name, $price) = $product;
        
        // quantity text input
        $qty_el = $frm->addinput('text', $abbr . '_qty', 0, 
            array('size'=>4, 'class'=>'cur', 'pattern'=>'[0-9]+', 'placeholder'=>0, 
                  'onchange'=>'getproducttotal(this)',
                  'onclick'=>'checkvalue(this)', 'onblur'=>'recheckvalue(this)') );
        
        // total text input
        $tot_el = $frm->addinput('text', $abbr . '_tot', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') );
        
        // price hidden input
        $price_el = $frm->addinput('hidden', $abbr . '_price', $price);
        
        $tbl->addrow();
            $tbl->addcell($name);
            $tbl->addcell(number_format($price, 2). ' kč' . $price_el, 'cur' );
            $tbl->addcell( $qty_el, 'qty');
            $tbl->addcell( $tot_el );
    }
    
    // total row
    $tbl->addrow();
        $tbl->addcell( 'celkem (kč): ', 'total', 'data', array('colspan'=>3) );
        $tbl->addcell( $frm->addinput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
        
        
    // additional fields for contact info
    $tbl->addrow();
        $tbl->addcell('jméno: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'first_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('příjmení: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'last_name', '', array('size'=>36,
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
        
    $tbl->addrow();
        $tbl->addcell('email: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'email', '', array('size'=>36,
                    'pattern' => '^[\w\+\'\.-]+@[\w\'\.-]+\.[a-za-z]{2,}$',
                    'required' => true
                    ) ), '', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('mobil: ', 'label');
        $tbl->addcell(
            $frm->addinput('text', 'phone', '', array('size'=>36,
                    'required' => true
                    ) ), 'last', 'data',
            array('colspan'=>3)
        );
        
    $tbl->addrow();
        $tbl->addcell('komentář: ', 'label');
        $tbl->addcell(
            $frm->addtextarea('comments', 4, 38, '',
              array('id'=>'comments', 'placeholder'=>'[komentář k objednávce]') )
        );

    // submit button
    $tbl->addrow();
        $tbl->addcell( $frm->addinput('submit', 'submit', 'odeslat objednávku'),
                'submit', 'data', array(&
    
Tomášeek
Profil
gully:
Zapni si výpis chybových hlášek a/nebo se podívej do error logu. Nikdo tu nebude procházet 200 řádků kódu.
gully
Profil
Díky moc. To s těma hláškama mi stačilo. Nedělám často v php.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: