Jump to content

Recommended Posts

Okay so I have this

 

index.php

<form action="test.php" method="post" name="shareform">
<textarea name="text"></textarea>
<a href="#" onclick="document.['shareform'].submit(); return false;">Go</a>
</form>
<?php session_strat(); echo $_SESSION['text'];?>

 

test.php

<?php
session_start();
$_SESSION['text'] = $_POST['text'];

 

But its not working, even after refresh of index.php, not processing correctly. Any ideas why?

 

Thanks for the help so far

You misspelled session_start():

 

<?php session_strat(); echo $_SESSION['text'];?>

 

You would also have to put session_start(); before any other output.

 

To access the form you need to use

 

document.forms['shareform']

 

not

 

document.['shareform']

okay now I have that working, now I am trying the AJAX/jQuery submit part

 

 

so I have this code

  /* attach a submit handler to the form */
  $("#shareform").submit(function(event) {

    /* stop form from submitting normally */
    event.preventDefault(); 
        
    /* get some values from elements on the page: */
    var $form = $( this ),
        term = $form.find( 'input[name="text"]' ).val(),
        url = $form.attr( 'action' );

    /* Send the data using post and put the results in a div */
$.post("test.php");
  });

 

but is seems not to be working, and Im not entirely sure why

 

FROM http://api.jquery.com/jQuery.post/

 

Thanks for all the help so far Alex

It would be the only thing you needed if you just wanted to request the page and do nothing else. But you want to request the page with the post data ($_POST['text']), and put the result of that request (whatever that file outputs) in a div, then you'll need something different.

 

"somedivid" would be the id of the div that you want to post the result of the response in, assuming that's what you want to do.

 

If I was mistaken and you don't want to do anything with the result of the request just remove the last parameter, the success function, from the $.post() call. Making it:

 

$.post(url, {'text': term});

Current code

    			<form action="test.php" id="shareform" method="post" name="shareform">
			<textarea id="share" name="share" onDblClick="alert('double clicked');"></textarea>
			<a href="#" onclick="document.forms['shareform'].submit(); return false;" class="share">Share</a>
		</form>

 

  $("#shareform").submit(function(event) {

    /* stop form from submitting normally */
    event.preventDefault(); 
        
    /* get some values from elements on the page: */
    var $form = $( this ),
        term = $form.find( 'input[name="share"]' ).val(),
        url = $form.attr( 'action' );

    /* Send the data using post and put the results in a div */
$.post(url, {'share': term});
  });

 

 

 

still NOT working

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.