0

So the problem is that i made a form on inde1.php and by using javascript i post data to login.php.

What i am trying to accomplish right now is when the login.php is executed and everything is ok to redirect user to another page.

on inde1.php the js is like this:

$(document).ready(function() {
      $("#myform").validate({
        debug: false,
        submitHandler: function(form) {
          $.post('login.php', $("#myform").serialize(), function(data) {
            checkFields(data);
            if(data!="ok")
            {
                 $("#myform")[0].reset();
                 grecaptcha.reset();
            }
            else
            {
                window.location.href = "pagetoredirect"
            }

          });

          return false; // if default form submission was not blocked, add this.
        }
      });
});

I was wondering if i could skip this part:

else
{
     window.location.href = "pagetoredirect"
}

and redirect users from login.php after login.php sends the "ok" to index1.php

10
  • How to make a redirect in PHP? Commented Nov 28, 2015 at 9:17
  • no you cant't. better to submit the form directly to php without using $.post Commented Nov 28, 2015 at 9:18
  • You need to validate your data in PHP and it is better than javascript validation and also necessary.After javascript validation send the data to php then validate it and for success and failure you can redirect the user to different page or same page with different messages . Commented Nov 28, 2015 at 9:20
  • well the validation is done on login.php, so you suggest that i should keep it as it is? with the ( window.location.href = "pagetoredirect" )? Commented Nov 28, 2015 at 9:22
  • U can't skip that part if you are using this code, but is there any reason why you want to? Commented Nov 28, 2015 at 10:17

1 Answer 1

1

well you can use header function it should be like lets say a page with a button on it

<form action='login.php' method='post'>
<input type='submit' value='submit' name='submit'>
</form>

and than on login.php page you can check if the button is pressed or not

<?php 
//for using header function it is important to use ob_start at the starting of php
ob_start();
if(isset($_POST['submit'])
{
//than use the header function
header ('location: profile.php')
//you will not even notice the opening of login.php and directly redirected to profile.php
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.