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>
</form>

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


PHP Code:

Code: Select all
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['type'])) {
$_SESSION['type'] = $_POST['type'];
//echo $_SERVER['REQUEST_METHOD'];
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?

Thanks!
raphael75
New php-forum User
New php-forum User
 
Posts: 17
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
kiash001
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

<?php
    session_start
();
    if (
$_POST) { //form was posted
    
echo '<pre>';
    
print_r($_POST);
    }
    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>
    </form>'
;
    }
 
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

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