Hack Forums
[PHP] How Would I Get an Echo'd Button to Redirect? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] How Would I Get an Echo'd Button to Redirect? (/showthread.php?tid=5932990)



How Would I Get an Echo'd Button to Redirect? - Effexion - Jan 23, 2019

PHP Code

<?php 
function CallButton() {
    global 
$con;
    
$email = $_POST['email']; 
    
$email = mysqli_real_escape_string($con, $email);
    
$at = "@";
    
$pos = strpos($email, $at);
    if(
$pos===false) {
        echo 
"Please enter a valid email address";
    }
    else {
    
    echo 
"<Thank you. Please click the button below to coninue.<br><br><input type='submit' name='openOffer' value='Proceed' class='btn btn-primary'>";
}
    } 

I'm trying to get it to redirect to a CPA offer but the button just disappears. My database gets updated first but I can't get it to redirect.


RE: How Would I Get an Echo'd Button to Redirect? - I337 - Jan 23, 2019

I think your "<" at the beginning can do that!


RE: How Would I Get an Echo'd Button to Redirect? - Effexion - Jan 23, 2019

(Jan 23, 2019 08:52 AM)thelastone1 Wrote:  I think your "<" at the beginning can do that!

How though and any idea why the button disappears?


RE: How Would I Get an Echo'd Button to Redirect? - Nachfolger - Jan 23, 2019

As for the button, check to verify it is being outputted, using Chrome inspector tools or something. Input tags must be closed with a forward slash and a right arrow (Idk the legitimate name) [Eg. /> ]

PHP has native functions to validate an email. I could literally just enter a @ into your little input and it would be valid. Use the functions. Please FOR MY SAKE do not use "im following a tutorial" as an excuse to perform lousy validations.


RE: How Would I Get an Echo'd Button to Redirect? - Squito - Jan 23, 2019

PHP Code

<?php 
function CallButton()
{
    if(
filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
    {
        echo 
'Thank you. Please click the button below to coninue.<br><br><input type="button" name="openOffer" value="Proceed" class="btn btn-primary" onClick="window.location='."'offer.php'".'">';
    }
    else
    {
        echo 
"Please enter a valid email address";
    }
} 



RE: How Would I Get an Echo'd Button to Redirect? - +Haze - Jan 23, 2019

Code
global $con;

For future references, be careful when using global variables like this, it isn't the best practice, it's really easy for you to make changes without actually knowing where changes are being made. A better approach would be to pass the connection object around in the parameters, use the singleton pattern or use dependency injection.


RE: How Would I Get an Echo'd Button to Redirect? - Effexion - Jan 23, 2019

(Jan 23, 2019 09:31 AM)Nachfolger Wrote:  As for the button, check to verify it is being outputted, using Chrome inspector tools or something. Input tags must be closed with a forward slash and a right arrow (Idk the legitimate name) [Eg. /> ]

PHP has native functions to validate an email. I could literally just enter a @ into your little input and it would be valid. Use the functions. Please FOR MY SAKE do not use "im following a tutorial" as an excuse to perform lousy validations.

I will look for a comprehensive list of all PHP functions. To be fair, I am just doing this from what I have learned so far. It's nothing to serious and was just having a mess around. I have decided to actually use it so will use the function.

(Jan 23, 2019 10:20 AM)Squito Wrote:  
PHP Code

<?php 
function CallButton()
{
    if(
filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
    {
        echo 
'Thank you. Please click the button below to coninue.<br><br><input type="button" name="openOffer" value="Proceed" class="btn btn-primary" onClick="window.location='."'offer.php'".'">';
    }
    else
    {
        echo 
"Please enter a valid email address";
    }
} 

Awesome. Thanks, man.

(Jan 23, 2019 10:59 AM)+Haze Wrote:  
Code
global $con;

For future references, be careful when using global variables like this, it isn't the best practice, it's really easy for you to make changes without actually knowing where changes are being made. A better approach would be to pass the connection object around in the parameters, use the singleton pattern or use dependency injection.

Appreciate the heads-up.