2

I'm trying to figure out how to modify the script from this existing subscribe form:

HTML

<form method="post" action="subscribe.php">
    <input type="text" name="email"/>
    <input type="submit" value="Submit" class="submit-btn">
    <input type="hidden" name="success" value="test-success.html">
    <input type="hidden" name="error" value="test-error.html">
</form>

PHP

    if (preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email))
    {
        if ($result && !empty($successUrl))
        {
            header( "Location: $successUrl") ;
        }   
        else if (!empty($errorUrl))
        {
            header( "Location: $errorUrl") ;
        }
        else
        {
            echo 'Error';
        }
    }
    else if (!empty($errorUrl))
    {
        header( "Location: $errorUrl") ;
    }
    else
    {
        echo 'Error';
    }

    exit();
}
?>

Rather than redirecting to the success/error page, I would like to show the message via popup.

The popup that I'm using is the Magnific Popup.

http://dimsemenov.com/plugins/magnific-popup/documentation.html

I've tried to edit the values from the input type & add in the popup link however it doesn't work tat way. I'm not good at php scripts either, may I know how should I make it work?

mark5
  • 553
  • 1
  • 9
  • 25

2 Answers2

0

You can go with the native Javascript alert box for displaying the pop-ups

else if (!empty($errorUrl))
    {
        echo "<script>alert('Error !');</script>";
        echo "<script>window.location.href=$errorUrl</script>";
    }
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
0

Your current setup has a HTML site redirect to a PHP script which then validates the data. PHP scripts are server-side and cannot show popups.

You should remodify your form so that it uses AJAX and posts the form in the background, and then shows a popup on success. You can do this with jQuery for example, see jQuery Ajax POST example with PHP for more info on how to do that.

Community
  • 1
  • 1
Andreas
  • 662
  • 1
  • 6
  • 13