Page 1 of 1

[SOLVED] "if" relatively simple question

Posted: Mon Jun 07, 2010 1:24 am
by eulogy
EDIT! Solved!

I used this method over here: http://www.codingforums.com/showthread.php?t=146487

------------------------------------

I have an html form that prints into a .csv file using php.

Code: Select all

<?php

$Name = $_POST['Name'];
$Company = $_POST['Company'];
$Email = $_POST['Email'];
$Phone = $_POST['Phone'];

$cvsData = $Name . "," . $Company . "," . $Email . "," . $Phone ."\n";
$fp = fopen ("signup.csv","a");
if($fp){
fwrite($fp,$cvsData);
fclose($fp);
} 
?>
Everything works, however I want to have a confirmation dialog-box, or for it to load another page after hitting submit.

The following code loads the page but I need to have a proper "if" which is where I'm having a little trouble.

Code: Select all

 print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.php\">";
I tried throwing it inside the if($fp){ but it just loads the confirmation page upon visiting the site.

Any help would be greatly appreciated, I'm sure there's a simple answer out there. All I need to know is how to do "If the data was submitted to the .csv (or even simply if the submit button was pressed?), then open this webpage". If you're feeling generous I'd also like to see how a dialog box would work, but I'm not too good with Javascript either.

Re: "if" relatively simple question

Posted: Mon Jun 07, 2010 3:49 am
by markusn00b
What is the purpose of the confirmation dialog? To confirm what? Do you want to confirm that the data is to be entered, or do you want to confirm that the data has entered successfully?

Re: "if" relatively simple question

Posted: Mon Jun 07, 2010 9:43 am
by Jonah Bron

Code: Select all

if($fp && isset($_POST['Name'])){
Also, you need to check the validity of your $_POST variables with isset().

Re: "if" relatively simple question

Posted: Mon Jun 07, 2010 10:00 am
by eulogy
markusn00b wrote:What is the purpose of the confirmation dialog? To confirm what? Do you want to confirm that the data is to be entered, or do you want to confirm that the data has entered successfully?
To confirm that the data was entered successfully. I don't think I need it to even check if it did or not, I just want the user to know so they don't try to type it again, as of right now it just clears the form but actually submits successfully.

I'm now trying this on my submit button,

[syntax]<input type="submit" name="submit" value="Submit" class="submit-button" onClick="alert('Thank you for signing up!')">[/syntax]

But this does not work either.

I've directly copied the code out of examples that DO work and I can't seem to get it to work for me :(

Re: [SOLVED] "if" relatively simple question

Posted: Mon Jun 07, 2010 10:19 am
by Jonah Bron
By "doesn't work", do you mean the alert box doesn't come up?