Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

form not posting

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

form not posting

Postby raphael75 » Fri Feb 15, 2013 6:34 am

We have a Debian Linux server with Apache2. One page, feedback.php has a super-simple form:

Code: Select all
<form action="feedback.php" method="post">
    <div class="type"><input type="radio" name="type" id="compliment" value="compliment" /><label for="compliment">Compliment</label></div>
    <div class="type"><input type="radio" name="type" id="complaint" value="complaint" /><label for="complaint">Complaint</label></div>
    <div class="type"><input type="radio" name="type" id="general" value="general" /><label for="general">General</label></div>
    <br />
    <input type="submit" name="submit" class="begin_comments" value="Begin Comments" />
    <br />
    <br />
    <br />
    <span class="error"></span>

This form posts back to itself, and handles it like this:

PHP Code:

Code: Select all

if (isset($_POST['type'])) {
$_SESSION['type'] = $_POST['type'];
header('Location: form.php');
else {
$error = 'You must select a comment type to begin';

However, when form.php loads, $_POST, $_GET, or $_REQUEST are all empty arrays. What could cause this?

New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: form not posting

Postby kiash001 » Wed Feb 27, 2013 3:42 am

Replace <input type="submit" name="submit" class="begin_comments" value="Begin Comments" /> into <button name="submit" class="begin_comments">Begin Comments</button>
I hope it will work!
User avatar
New php-forum User
New php-forum User
Posts: 16
Joined: Wed Feb 27, 2013 2:49 am
Location: Dhaka, Bangladesh

Re: form not posting

Postby seandisanti » Wed Feb 27, 2013 9:44 am

it's because you're navigating to form.php by changing the header, not by submitting the form.
Code: Select all

    if (
$_POST) { //form was posted
echo '<pre>';
    else { 
//not responding to form 
echo '<form action="' $_SERVER['PHP_SELF'] . '" method="post">
        <div class="type"><input type="radio" name="type" id="compliment" value="compliment" /><label for="compliment">Compliment</label></div>
        <div class="type"><input type="radio" name="type" id="complaint" value="complaint" /><label for="complaint">Complaint</label></div>
        <div class="type"><input type="radio" name="type" id="general" value="general" /><label for="general">General</label></div>
        <br />
        <input type="submit" name="submit" class="begin_comments" value="Begin Comments" />
        <br />
        <br />
        <br />
        <span class="error"></span>
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.