Page 1 of 2
posting from the form problem ! ???
Posted: Wed Jun 20, 2007 4:04 pm
by nita
Hi,
i have a problem with the posting from the form.
I have recommendation form with captcha, wich i think there is no problem with. Once i press submit, php take action in another if else condition with out passing variable, i quite can figure it out why is like this. Take a look the code, please ....
Code: Select all
if(isset($_GET['cat'])) // when looking at selected category
{
} //problematic submit goes here ...
else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
}
else //when looking at the root of the aplication
{
// some code
if($_POST['submitform']) // problematic submit expected to start here....
{
$yourcode=$_POST['yourcode'];
$thevalue1=$_POST['thevalue'];
if($yourcode=$thevalue1)
{
mail($myemail,$subject,$messagetoemail,$name);
mysql_query ("INSERT INTO moviesreco (id, name, email, message)
VALUES ('', '$name', '$email', '$messagehtml')");
echo "$thanks";
}
else
{
echo "You verification code is not right. Please go back and try again.";
}
}
else
{
//this is recomandation form
echo "
<form action='$PHP_SELF' method='post'>
<input name='name' size='30'>
<input name='email' size='30'>
<textarea name='message' rows='10' cols='30'></textarea>
";
$im = ImageCreate(60, 20); //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
echo "
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue'>
<input type='text' name='yourcode' size='5' maxlength='5'>
<input class='button1' type='submit' value='Send' name='submitform'>
<input class='button1' type='reset' value='Reset' name='reset'>
</form>
";
}
// some more code
}
I need some help on this one, please !!!
thank you in advance.
Nita
Posted: Wed Jun 20, 2007 4:48 pm
by superdezign
What?
You're question isn't making much sense. Maybe you could clear it up and give a more pinpoint portion of code.
Posted: Wed Jun 20, 2007 5:00 pm
by nita
so to clear it up:
i have recomendation form with captcha, after submiting php is expected to check if captcha = input and then display any kind of confirmation information or error,
problem is once i press submit button action is not taken in if ($_POST['submitform']) bu int if else condition for search part of aplication.
for current working version go to
http://www.nita-on-line.com/movies.phpa
thanks a lot
nita
Posted: Wed Jun 20, 2007 5:07 pm
by superdezign
Firstly, you don't check if $_POST['submitform'] is checked before checking it. Also, have you tried outputting your $_POST array and seeing what you're missing?
Posted: Wed Jun 20, 2007 5:12 pm
by Weirdan
that captcha is useless since it outputs the string, that supposed to be on the pic, in plain text, so... why bother doing that?
ok, hm something new
Posted: Wed Jun 20, 2007 5:24 pm
by nita
well since im kind of new to php, i had no qlue that this captcha i completly usesles.
You are very right , will you be kind to suggest something else.....
still, if at the moment i like to stick to what is now
i have a problem of submiting from form - wrong action, there must be some error ....
could you take a look .. please ..
thank you very much
nita
Posted: Wed Jun 20, 2007 5:28 pm
by nita
superdezign wrote:Firstly, you don't check if $_POST['submitform'] is checked before checking it. Also, have you tried outputting your $_POST array and seeing what you're missing?
what it does, could you give me some more code ??
Posted: Wed Jun 20, 2007 6:28 pm
by nita
part of the code where i did put it ...
Code: Select all
print_r($_POST); if($_POST['submitform']) {
browser is returning
Array ( )
thank you for your help
to see what i mean go to
http://www.nita-on-line.com/movies.php
nita
Posted: Wed Jun 20, 2007 6:33 pm
by superdezign
print_r() displays the contents of an object, array, or variable. $_POST is an array. Try submitting your form, and then look at it.
Posted: Wed Jun 20, 2007 6:39 pm
by nita
when i press submit button, browser is moving to the search part of aplication, and diplay error, wich i know is a result of empty search string, which means that no inforamtion has been passed,
i also have to admit that i have 2 forms, 1 recomendation (problematic on) and serch and i think this is where confusion comes,
thanks for help
nita
Posted: Wed Jun 20, 2007 6:56 pm
by superdezign
... Ya lost me.
Basically, echo all of your variables to the screen and debug. Something isn't working the way that you think it should be, o find out exactly what it is.
im lost myself
Posted: Wed Jun 20, 2007 7:20 pm
by nita
there is a bit of improvment now, i manage to get form to right if else condition.
But still have a problem couse at the time browser displying me automaticly that i have sent recomendation.
is not showing form any more. I dont understand why ?
????
code...
Code: Select all
else // if looking at hte root of aplication
{
if(!isset($_POST['submitform']))
{
$myemail = "kris@nita-on-line.com";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$messagehtml = str_replace("\r", '<br/>', $message);
$thanks = "
<p align='left' class='info2'><span class='info2'>
Thank you !. Your recomendation has sucessfuly been sent!<br>
<br></span></p>";
$subject = "New Movie Recomendation from $Name";
$messagetoemail = "Hi Kris. You recived a new movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";
$yourcode=$_POST['yourcode'];
$thevalue1=$_POST['thevalue1'];
if($yourcode==$thevalue1)
{
echo "$thanks";
}
else
{
echo "You verification code is not right. Please go back and try again.";
}
}
else
{
//this is recomandation form
echo "
<table width='100%' border='0' cellspacing='0' cellpadding='10'>
<tr>
<td>
<form action='$PHP_SELF' method='post'>
<table width='444' align='left' class='info4'>
<tr>
<td valign='top' align='right'><b>Name:</b></td>
<td valign='top'>
<input name='name' size='30'>
</td>
</tr>
<tr>
<td valign='top' align='right'><b>E-mail:</b></td>
<td valign='top'>
<input name='email' size='30'>
</td>
</tr>
<tr>
<td valign='top' align='right'><b>Recomendation:</b></td>
<td valign='top'>
<textarea name='message' rows='10' cols='30'></textarea>
</td>
</tr>
<tr>
<td>";
$im = ImageCreate(60, 20); //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
echo "
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue1'>
</td>
<td>
<input type='text' name='yourcode' size='5' maxlength='5'>
</td>
</tr>
<td valign='top' align='right'></td>
<td valign='top' align='left'>
<input class='button1' type='submit' value='Send' name='submitform'>
<input class='button1' type='reset' value='Reset' name='reset'>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table><br>";
}
}
hope this is more helpfull
nita
Posted: Thu Jun 21, 2007 3:22 am
by nita
Problem - when i press submit button php is taking action as if i will press submit button of search form.... and goes to search else if part of code
Current code.
Code: Select all
if(isset($_GET['cat'])) // when looking at selected category of movies
{
}
// when i press submit button on the recomendation form php goes here
else if(isset($_POST['submit'])||isset($_POST['search'])||isset($_GET['search'])) // when search button is pressed
{
}
else //when looking at the root of the aplication
{
if ($_POST['submitform'])
{
$myemail = "kris@nita-on-line.com";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$messagehtml = str_replace("\r", '<br/>', $message);
$thanks = "
<p align='left' class='info2'><span class='info2'>
Thank you !. Your recomendation has sucessfuly been sent!<br>
<br></span></p>";
$subject = "New Movie Recomendation from $Name";
$messagetoemail = "Hi Kris. You recived a new movie recomendation.
Name: $name
E-mail: $email
Recomendation: $messagehtml
";
$yourcode=$_POST['yourcode'];
$thevalue1=$_POST['thevalue1'];
if($yourcode==$thevalue1)
{
echo "$thanks";
}
else
{
echo "You verification code is not right. Please go back and try again.";
}
}
else
{
// recomendation form
<form action='movies.php' method='post'>
<input name='name' size='30'>
<input name='email' size='30'>
<textarea name='message' rows='10' cols='30'></textarea>
$im = ImageCreate(60, 20); //create image
$white = ImageColorAllocate($im, 0,0, 0);
$black = ImageColorAllocate($im, 120, 200, 68);
$md5 = md5(microtime() * mktime());
$string = substr($md5,0,5);
$verification = $string;
$thevalue= $string;
ImageFill($im, 0, 0, $black);
ImageString($im, 4, 10, 3, $verification, $white);
Imagejpeg($im, "inc/verify.jpeg");
ImageDestroy($im);
<img src='inc/verify.jpeg' border='0'>
<input type='hidden' value='$thevalue' name='thevalue1'>
<input type='text' name='yourcode' size='5' maxlength='5'>
<input class='button1' type='submit' value='Send' name='submitform'>
<input class='button1' type='reset' value='Reset' name='reset'>
}
}
i'm well stuck on this.
i have to say that once i keep this recomendation seaperate ( not beetween
else { } ) is working with no problem,
i don't understand why php is moving to search part of the code...
i need some help ....
nita
Posted: Thu Jun 21, 2007 5:40 am
by superdezign
Whatever it is, it's due to bad logic in your if statements. I'd suggest rewriting it piece by piece and testing each portion separately, It'll tend to "fix itself" that way.
Posted: Thu Jun 21, 2007 6:15 am
by Styx
It seems that it'll move to the "search" part of the script if any of this is true: isset($_POST['submit']), isset($_POST['search']), or isset($_GET['search']), so you need to check if any of those are being submitted somehow. Check your names and check your url bar. Your last script works fine for me.