Jump to content

Submitting a form to the same page: HELP


gniterobot

Recommended Posts

Hi,

I am essentially trying to create a page where this would work...

<?
$name = $_POST['name'];

if($_POST['_submit_check'])
{
print $name;
}

?>
....

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
NAME: <input name="name" type="text" />
<input type ="hidden" name="_submit_check" value="1" />
<input type="submit" />

The problem seems to be that it works once, then defaults every time after to not recognizing the name.

So you could imagine the first time a user sees a form, he types "Mike" and hits submit.  then he sees MIKE and the form.  then if he type "Susy" and hits submit it SHOULD say Susy and print the form, but it doesn't.  How do I make it so the same page can be submitted to time and time again?

Thanks in advance!

-Matt
Link to comment
Share on other sites

Instead of having the hidden field, give the submit button a name and check for that:
[code]<?php
if (isset($_POST['submit']))
  echo 'Name: ' . $_POST['name'] . '<br>';
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
NAME: <input name="name" type="text" />
<input type="submit" name="submit" />
</form>
[/code]

Ken
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=116185.msg473231#msg473231 date=1164399142]
if($_POST['_submit_check'] == 1)
[/quote]

This isn't quite my problem.

The problem is that it works the first time, then the next time they try to use the form it won't use the updated name.

I cn verify that the first time the enter the page no name is printed, that is fine.  But how can I make it so the page can be used over and over?
Link to comment
Share on other sites

My original post explains it best...

So from that sample code you should be able to navigate to the page and the first time the form is printed but no name (obviously).

The person types in their name and hits submit, now their name is printed followed by the form.  They then type a NEW name and click submit.  It SHOULD print the new name and the form.  But instead it only prints the form and no name, as if it was the first time they went to the page.


It's a simplier version of the problem I having, but they are identical is nature.  How can I make it so every time the submit the page updates with the new information??


Ok it appears it's a time issue.

So if I wait 5 minutes or so and resubmit it works, but if I type a new name and resubmit right away it returns to the default screen..Anyway around this?
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.