Form process on same page

I am trying to process html form which is in file something.php. This page will have
<div>Thanks for submitting the form</div> hidden by CSS

 div {
     display: none;
 }

On the successful submit I will like to display this message by setting display: block for example but the problem i am finding is that on submit this page (something.php) refreshes and my message from above immediately disappears. Is there any way I can resolve this without using different.php script or Ajax?

Thanks

you could use the PHP session to define a success value.

Can you show me pseudo code if you don’t mind on what would that look like

PHP

if form-success
  session-success = true
else
  session-success = false

Template

if session-success
  display block
else
  display none

Yes but from above it looks like you have 2 files?

I usually do content-code separation, so my form processing is not done in the HTML template.

1 Like

My page that has form on contains some php code already so I was hoping to keep everything within same file

As far as I know, when you do a form submit, whether it’s to the same PHP source file or to another one, you’ll get a page refresh which is what I don’t think you want. So the alternative is that you use Ajax to submit the form, set your div to ‘block’ at the start of the button handling code, and then deal with whatever response comes from the separate PHP code. I guess you could have it in the same file but I can’t see why you’d want to.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.