Jump to content

How to debug a form?


norm101

Recommended Posts

Hi All -

 

I created a Hello World project consisting of a form and a PHP page that is called when a Submit button is pressed.  I've tried debugging this with Eclipse/Zend debugger and phpDesigner.  With both tools, when Submit is pressed, my breakpoint in the 2nd form does not get triggered.  Instead, the debugger just displays the name of the PHP file.

 

So, how can I debug a simple scenario like this?

 

Thanks,

Norm

Link to comment
Share on other sites

I've recently come across compilers for PHP where you can make portable cross-platform independant exectuable applications (phew..), or simply put: .exe files.

 

One i tried recently (did not compile properly for me) which had a nice working debugging step/trace tool was Roadsend IDE.

 

Hope this helps.

 

EDIT: I see you want a debugger where you can go through it like a website whilst looking at the call stack etc. You may need to manually pass arguments to the script.

Link to comment
Share on other sites

Form.php

 

<html>

<body>

<form action="registration_action.php" method="post">

Name: <input type="text" name="name" />

Age: <input type="text" name="age" />

<input type="submit" />

</form>

</body>

</html

 

-------------------------------------

registration_action.php

 

<html>

<body>

Welcome <?php echo $_POST["name"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old.

</body>

</html>

Link to comment
Share on other sites

<?php session_start(); ?>
<html>
<body>
<form action="registration_action.php" method="post" name="lalal">
Name: <input type="text" name="name">
Age: <input type="text" name="age">
<input type="submit">
</form>
</body>
</html

 

registration_action.php

<?php 
session_start();
$_SESSION['name'] = $_POST["name"];
$_SESSION['age'] = $_POST["age"];
$name = $_SESSION['name'];
$age = $_SESSION['age'];
?>
<html>
<body>
Welcome <?php echo $name; ?>.<br />
You are <?php echo $age; ?> years old.
<?php session_destroy(); ?>
</body>
</html> 

Link to comment
Share on other sites

hmm, your original script should work flawlessly.

 

try putting:

 

<?php print_r($_REQUEST); ?>

 

On the registration_page.php anywhere. it will echo the contents of any custom data (like form data) sent to the server from the browser. (like POST or GET data).

 

if its empty try setting the form method to GET and see if that helps. (GET is sent via the URL, POST is sent underneath i believe in some headers sent to the server (along with the browser version etc etc).

Link to comment
Share on other sites

Thanks to all that responded.  Yes, the code does work flawlessly.

 

I'm trying to set up my debug environment and I don't understand why the debugger doesn't hit my breakpoint in the second file?  When I click the submit button, the only output from the debugger is the name of the second file???

 

Can anyone recommend a debugger that will enable me to step-through a simple scenario like this?

 

Norm

Link to comment
Share on other sites

try this way mate. one whole page.php

<html>
<body>
<?php if(isset($_POST['submit'])){
echo "Welcome {$_POST["name"]} <br />
You are {$_POST["age"]} years old.";
}?>

<form action="registration_action.php" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" name="submit" value="SEND!"/>
</form>
</body>
</html>

Link to comment
Share on other sites

YES, yes!!

 

I've tried both Eclipse/Zend and phpDesigner with the same result, so I'm thinking it isn't a tool problem but something else I'm missing.  I'm new to PHP programming, but I think this has got to be a pretty common debugging scenario and it should be straightforward to debug via stepping through code.

 

Norm

Link to comment
Share on other sites

Ok i get you now, zend and other php programs need to be configured to use your current test server to use the debugging screen properly.

 

i dont use the debugung screen to test my submitted results i save the file then use a proper url to the page.

 

you need to read the zend manual to setup the server part off the zend program or other programs m8.

 

that what you mean....

 

i also get the url in the debug page pressing the button, but that becouse i haven set my zend to point to my proper testing server.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.