This makes no sense

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

This makes no sense

Post by Cirdan »

Okay I have this form:

Code: Select all

<form action="logic/page.php" method="post" accept-charset="utf-8">    <p>Title: <input type="text" name="title" value="<?=$data['title']?>"  maxlength="<?=MAX_PAGE_TITLE_LENGTH?>" /></p>    <p>Body:<br /> <textarea rows="15" cols="50" name="body"><?=$data['body']?></textarea>            <p><input type="submit" name='button' value="Preview" />    <input type="submit" name='button' value="Continue &rarr;" /></p></form>
logic/page.php looks like this:

Code: Select all

<?php
session_start();
 
define('IN_SITE', 1);
 
require_once '../includes/functions.php';
 
print_r($_POST);
 
if(isset($_POST["button"]) && $_POST["button"] == 'Preview')
{
    setFormData($_POST);
    header('Location: page.php?mode=add');
    exit;
}   
 
echo 'fail';
Here is the problem. You see the print_r statement? When that statement is there, I can see that 'button' is set and the if statement returns true and the block of code is executed. Without the print_r statement, the if statement is false because 'button' doesn't exist and "fail" gets printed. This makes no sense at all.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: This makes no sense

Post by greyhoundcode »

Doesn't seem to make much sense, does it? Because I don't have functions.php to include, I removed that line and also replaced the first two lines from inside the if block with echo 'success';.

Unlike you, I found that removing print_r() made no difference whatsoever to the logical outcome. That makes me think that a problem exists with either the setFormData() function, or the code within page.php, or possibly both.

Hope that is of some help?
Cirdan
Forum Contributor
Posts: 144
Joined: Sat Nov 01, 2008 3:20 pm

Re: This makes no sense

Post by Cirdan »

Okay, looks like it is the header statement. Am i creating some sort of loop accidentally with the form?
Post Reply