Jump to content

Recommended Posts

Hi,

I'm validating a form by posting the form to itself, which means if the form is valid it just comes back from the server the same, is there a way i can post if valid.  Basically I want to be able to do the following after submitting the form to itself and processing the validation:

if (valid)
  show next.php
else
  print error messages

Thanks in advance

Dean
Link to comment
https://forums.phpfreaks.com/topic/14467-posting-without-clicking-submit/
Share on other sites

I'm not sure if this will work, but could you do it with a mix of JavaScript and PHP?
[code]if(valid) {
    echo "<script type='text/javascript'>document.myformname.submit();</script>";
} else {
    //print error messages
}[/code]
Alternatively, you could store the information you want to pass within a session variable, or even pass it through the URL...
Hmm.. I think now I got what he trying to ask, hope I got it right now.

You create your form scripts, then name the submit "submit".
And your form post method is [b]<?php echo $_SERVER['PHP_SELF']; ?>[/b]

So you just need to do this,
[code]if (isset($_POST['submit'])) {
  // show next page
} else {
  // echo error
}[/code]
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.