Jump to content

PHP Beginners Help


graeme_1988

Recommended Posts

Hi,

 

I rarely deal with PHP, so this may sound very easy, but I am struggling to figure out what to do. Basically I have created a website for a client that allows for customers to pay for certain packages using Paypal. They select the package they want, which then takes them to a data input page (email, tel no, name etc). Once they click submit, that information gets emailed to my client, and the customer is presented with the relevant Paypal page.

 

What I need is on each data input page, for a checkbox to be available, so if the customer checks the checkbox, they get taken to a different paypal page rather than if they leave it blank.

 

So really, what I need is if the checkbox is left blank and that page is submitted, the customer goes to Page A. If the checkbox is checked and they click submit, the customer goes to Page B.

 

Any help would be greatly appreciated!

 

Cheers

 

Graeme

Link to comment
Share on other sites

You could send everyone to Page A. Then if the checkbox was clicked redirect them to Page B using header().

http://php.net/manual/en/function.header.php

 

 

You could also look into using JavaScript. You should be able to modify where the form goes on the fly with JavaScript when someone clicks the checkbox. Off hand, I don't know what that code would be.

 

If you decide to use a JavaScript solution, I would still recommend utilizing the PHP solution mentioned above as a backup. That way if JavaScript is turned off or doesn't work, the PHP solution would still redirect visitors.

Link to comment
Share on other sites

I managed to get it to work, so that the value of the checkbox determines the page the user will come to. However, now the email doesn't get sent. I'm assuming it is because I am declaring variables twice, or perhaps it is because the message send part of the code is repeated, but I've tried a few different ways and it still doesn't work.

 

I have pasted my code below (I imagine some of the more experienced PHP experts out there will have a fit when they see how poor/messy it is!). Any help would be much appreciated!

 


<?php

$YourEmail = "emailaddress@hotmail.co.uk";      
$WebsiteURL = " ####.html";  
$subject = "Subject";      


if (empty ($_POST['agree'])) {



if(!isset($_POST['email'])) {
header("location: $WebsiteURL");
exit();
}


$_POST['name'] = preg_replace("/[\n\r]+/", "", $_POST['name']);
$_POST['email'] = preg_replace("/[\n\r]+/", "", $_POST['email']);


## THE EMAIL TEXT
$text = "
-----------------------------------------------------------------------------
  Title Text
-----------------------------------------------------------------------------

Name: ".$_POST['name']." \n\n
Email: ".$_POST['email']." \n\n
Past Experience: ".$_POST['exp']." \n\n
Area: ".$_POST['area']." \n\n
Contact Number: ".$_POST['phone']." \n\n
Referral: ".$_POST['referral']." \n\n



";

    $subject = stripslashes($subject);
    $text = stripslashes($text);
@mail("$YourEmail", $subject, $text, "From: <$subject>");


After
header("Location:  ####.html");
exit;

}

else {


if(!isset($_POST['email'])) {
header("location: $WebsiteURL");
exit();
}


$_POST['name'] = preg_replace("/[\n\r]+/", "", $_POST['name']);
$_POST['email'] = preg_replace("/[\n\r]+/", "", $_POST['email']);


## THE EMAIL TEXT
$text = "
-----------------------------------------------------------------------------
   Title text
-----------------------------------------------------------------------------

Name: ".$_POST['name']." \n\n
Email: ".$_POST['email']." \n\n
Past Experience: ".$_POST['exp']." \n\n
Area: ".$_POST['area']." \n\n
Contact Number: ".$_POST['phone']." \n\n
Referral: ".$_POST['referral']." \n\n



";

    $subject = stripslashes($subject);
    $text = stripslashes($text);
@mail("$YourEmail", $subject, $text, "From: <$subject>");


After
header("Location: ####.html");
exit;




}

?>

 

Just to reiterate - the user will enter their details on a form, then click submit. The data then gets emailed to the client. If they check the checkbox, they will then get sent to "page a", if they leave it blank, then they get sent to "page b".

 

Cheers!

 

Graeme

Link to comment
Share on other sites

Yeah the 'after' part was something I had commented in - I tried to remove all comments when I pasted it on here, so sorry about that!

 

The 'from subject' part worked fine before - it just meant that when someone sends the form, and the client receives the email, it says it is from 'Website User Capture Page etc'.

Link to comment
Share on other sites

Php is good and easy to learn. I just learnt it when I started my freelancing jobs.

 

2 posts and both contain a link to your website, trying to boost your low PageRank website through this high-volume forum?

 

Haha there's always one that tries it

Link to comment
Share on other sites

Do you know which part of the code is getting executed? One way to find out is to display something on the screen in the various if statements. Note that you'll want to comment out the redirects so that you see the messages. For example, you could do something like this:

 

<?php
...

if (empty ($_POST['agree'])) {
    print 'here - agree';
    ...

} else {
    print 'here - agree blank';
    ...

}

...
?>

 

 

You could also look into removing the @ before the mail() functions. The @ surpresses errors which might provide a clue as to why the e-mail isn't being sent.

 

 

You might want to consider adding an if around the mail() functions so that the redirect doesn't happen if the e-mail isn't sent.

 

<?php
...

if(mail("$YourEmail", $subject, $text, "From: <$subject>")) {
     header("Location: ####.html");
     exit;
} else {
     //<-- display error about there being a problem sending the e-mail and/or log error
}

...
?>

Link to comment
Share on other sites

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.