Jump to content

PHP cookie and form


razorsese

Recommended Posts

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>



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.