codingmasterRS Posted June 12, 2011 Share Posted June 12, 2011 Hi, I have tried this <a href="document.['formname'].submit(); return false;">Go</a> except it is returning a Not Found, as it redirects the browser to http://mydomain.com/document.%5B%27shareform%27%5D.submit%28%29;%20return%20false; Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/ Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 That should be the value of the onclick attribute, not href. Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228658 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228660 Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 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'] Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228662 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228664 Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 You'll need to specify the data to be sent in the request, and a callback function to be called when the response returns. Something like this: $.post(url, {'text': term}, function(data) { $('#somedivid').html(data); }); Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228667 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 what would #somedivid be?? Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228668 Share on other sites More sharing options...
Alex Posted June 12, 2011 Share Posted June 12, 2011 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}); Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228669 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 I just want to post the field off to text.php for placing in a session and thats it, no auto refresh no place auto in div Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228670 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228671 Share on other sites More sharing options...
codingmasterRS Posted June 12, 2011 Author Share Posted June 12, 2011 It needs to work like an AJAX submission, so you NEVER leave this page once the data is submitted or as it is being submitted. Quote Link to comment https://forums.phpfreaks.com/topic/239139-link-as-submit-button/#findComment-1228673 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.