PC Nerd Posted May 20, 2007 Share Posted May 20, 2007 hi guys, is it possible to send a form data to a page, using a link instead of a button? id prefer not to have to rely on javascript, so i would like it to be ras html, or the like...... thanks for the help yours, PC Nerd Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/ Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 Not a php question, so wrong section Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257494 Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Author Share Posted May 20, 2007 well can it be defined in php or something when it displays the form...... or do i have to rely entirely on the client? Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257495 Share on other sites More sharing options...
pocobueno1388 Posted May 20, 2007 Share Posted May 20, 2007 I don't think it's possible to send form data through a simple text link in PHP. Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257497 Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Author Share Posted May 20, 2007 thanks..... so i would have to use javascript to actually add the data into post....... btw, if anyone knows how to directly write to POST, or a tutorial / example. would you be able to leet me know ( i know its the wrong section, but while this posts here, its better than making a new on elsewhere) ( GET is easy as you simply append to the url) thanks for your help Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257500 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 to send a post your need to understand sockets A simple HTTP request class using socket. <?php class HttpRequest { var $sHostAdd; var $sUri; var $iPort; var $sRequestHeader; var $sResponse; function HttpRequest($sUrl) { $sPatternUrlPart = '/http:\/\/([a-z-\.0-9]+)(\d+)){0,1}(.*)/i'; $arMatchUrlPart = array(); preg_match($sPatternUrlPart, $sUrl, $arMatchUrlPart); $this->sHostAdd = gethostbyname($arMatchUrlPart[1]); if (empty($arMatchUrlPart[4])) { $this->sUri = '/'; } else { $this->sUri = $arMatchUrlPart[4]; } if (empty($arMatchUrlPart[3])) { $this->iPort = 80; } else { $this->iPort = $arMatchUrlPart[3]; } $this->addRequestHeader('Host: '.$arMatchUrlPart[1]); $this->addRequestHeader('Connection: Close'); } function addRequestHeader($sHeader) { $this->sRequestHeader .= trim($sHeader)."\r\n"; } function sendRequest($sMethod = 'GET', $sPostData = '') { $sRequest = $sMethod." ".$this->sUri." HTTP/1.1\r\n"; $sRequest .= $this->sRequestHeader; if ($sMethod == 'POST') { $sRequest .= "Content-Type: application/x-www-form-urlencoded\r\n"; $sRequest .= "Content-Length: ".strlen($sPostData)."\r\n"; $sRequest .= "\r\n"; $sRequest .= $sPostData."\r\n"; } $sRequest .= "\r\n"; $sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!$sockHttp) { die('socket_create() failed!'); } $resSockHttp = socket_connect($sockHttp, $this->sHostAdd, $this->iPort); if (!$resSockHttp) { die('socket_connect() failed!'); } socket_write($sockHttp, $sRequest, strlen($sRequest)); $this->sResponse = ''; while ($sRead = socket_read($sockHttp, 4096)) { $this->sResponse .= $sRead; } socket_close($sockHttp); } function getResponse() { return $this->sResponse; } function getResponseBody() { $sPatternSeperate = '/\r\n\r\n/'; $arMatchResponsePart = preg_split($sPatternSeperate, $this->sResponse, 2); return $arMatchResponsePart[1]; } } ?> Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257504 Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Author Share Posted May 20, 2007 ok, thanks for the code, ill try and go learn about sockets, however im short on time, so i may just rely on javascript etc....... or simply use a button... appreciate the fast replies, Link to comment https://forums.phpfreaks.com/topic/52207-solved-passing-post-data-on-link-click-and-not-form-button/#findComment-257512 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.