razorsese Posted April 12, 2012 Share Posted April 12, 2012 I got a weird problem; I got a form whit 2 fields and a submit button; When i click the submit button a jquery ajax script create a cookie named form; My problem is the form isn't disappearing when i click the submit(javascript is set to reload location) button even when i try to delete the cookie from the browser; on index: function addcomment($pass , $pst)//add comment and call form { $cpageid = $pass; $comment = new Comment; $comment->storeFormValues($pst); $comment->insertc(); require('comment.php'); } on the page where the form is called: <div id="commentbox" class="container_24"> <?php if(!isset($_POST['form'])) { addcomment($result['article']->id,$_POST);//addcoment on the page whit the current id } ?> </div> Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/ Share on other sites More sharing options...
scootstah Posted April 12, 2012 Share Posted April 12, 2012 What do you mean the form isn't "disappearing"? Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336692 Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 I got a weird problem; I got a form whit 2 fields and a submit button; When i click the submit button a jquery ajax script create a cookie named form; My problem is the form isn't disappearing when i click the submit(javascript is set to reload location) button even when i try to delete the cookie from the browser; on index: function addcomment($pass , $pst)//add comment and call form { $cpageid = $pass; $comment = new Comment; $comment->storeFormValues($pst); $comment->insertc(); require('comment.php'); } on the page where the form is called: <div id="commentbox" class="container_24"> <?php if(!isset($_POST['form'])) { addcomment($result['article']->id,$_POST);//addcoment on the page whit the current id } ?> </div> It's quite impossible to say what is wrong, because so much of your code is missing, but if I had to give it a guess, then it's because the Comment class is in the included file called comment.php. PHP reads from top to bottom, and the comment.php file is not included before after you try to use the Comment class to create a new object. Instead of this: $comment = new Comment; $comment->storeFormValues($pst); $comment->insertc(); require('comment.php'); Try this: require('comment.php'); $comment = new Comment; $comment->storeFormValues($pst); $comment->insertc(); Also turning on error reporting would have given you a clue about what is wrong. Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336694 Share on other sites More sharing options...
razorsese Posted April 12, 2012 Author Share Posted April 12, 2012 Sorry for my late relply; Well if i change the isset and whit a cookie active the form isn't appearing Actually in the 'comment.php' is the form needed to display if( isset($_POST['form'])) { addcomment($result['article']->id,$_POST);//addcoment on the page whit the current id } The 'comment.php' code: <form id="commentform" method='post' action="index.php?action=viewArticle&articleid=<?php echo $cpageid;?>" > <input type="hidden" name="id" class='cid' value="<?php echo $cpageid;?>"/> <p> <input type="text" name="usern" class='usern' maxlenght='40'/> <label for="usern">Username</label> </p> <p> <textarea name="com" class='com' COLS=40 ROWS=6></textarea> <label for="com">Comment</label> </p> <input type="hidden" name="page" class='page' value="<?php echo $cpageid;?>" /> <p> <input type="submit" name="submit" class='submit' value="Submit" /> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336755 Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 Enable error reporting! Put this at the very start, only after <?php, in the file your script starts at. error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336760 Share on other sites More sharing options...
razorsese Posted April 12, 2012 Author Share Posted April 12, 2012 No error appear Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336763 Share on other sites More sharing options...
razorsese Posted April 12, 2012 Author Share Posted April 12, 2012 if(!isset($_POST['form'])) it if( !isset($_COOKIE['form'])) Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336767 Share on other sites More sharing options...
scootstah Posted April 12, 2012 Share Posted April 12, 2012 Honestly, I still have no idea what you're trying to do. Try explaining your question better, and posting code that's actually relevant. Quote Link to comment https://forums.phpfreaks.com/topic/260805-php-cookie-and-form/#findComment-1336776 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.