Form posting to multiple locations

by 7 replies
9
Trying to get this form to post to my db with process.php and to another website using POST. Right now it will only load the second f.action. If I remove the first f.submit() it only does the first f.action. Any idea on getting this to work?


<script type="text/javascript">
<!--
function newWin(f)
{

f.target="_blank";
f.action="process.php?mobile_no=";
f.submit()
f.target="_blank";
f.actuon="secondsite"
f.submit();
return true;



}
//-->
</script>



</head>

<body>


<div data-role="page" id="page">


<form method="POST" action="secondsite" onsubmit="newWin(this)">



<div data-role="content">




<center>
<p><input type="text" id="mobile_no" name="mobile_no" placeholder="Phone Number"></p>


</center>
<p><input type="submit" value="Submit"></p>


</div>



</form>


</div>
#programming #form #locations #multiple #posting
  • Use ajax to push the data into your own local database, and let the form submit as normal.
    • [ 1 ] Thanks
  • [DELETED]
  • do it with JQUERY $.POST() .. easy.
    • [ 1 ] Thanks
    • [2] replies
    • By using Ajax, you can do it, just get the mobile_no value using document. getElementById("mobile_no") .value. and using xmlHttp.open("GET",url,true); you can save in your database.
      url will be contains ur file name with path.in that file u can get the value and save it.
      • [ 1 ] Thanks
    • would that be like this?
      $.post('process.php', function(data),'site2', function(data) { $('.result').html(data); });
      or
      $.post('process.php','site2' function(mobile_no) { $('.result').html(mobile_no); });
      I'm not too familiar with jquery and have light work with ajax. Thanks for all the replies guys!
      Oh, I forgot in the original post that I was also trying to have "site2" open either in _self or _blank and all I need for process.php is for it to submit

      Or would I be able to add some type of forwarder into process.php?
      <?
      $mobile_no=$_POST['mobile_no'];

      mysql_connect("localhost", "dbuser", "dbpass) or die(mysql_error());
      mysql_select_db("dbname") or die(mysql_error());
      mysql_query("INSERT INTO `data` VALUES ('$mobile_no')");
      Print "Your information has been successfully added to the database.";

      ?>
  • Its not supposed to be possible to do that.

    with javascript you will find you will have problems posting to/from the www. and non-www. version of the site because javascript considers THAT cross-domain.

    better to re-think your plans.

    Perhaps open a window on the other site with a unique identifier that tells that site that your site has new info for it, then transfer via xml or json the data that you want with the server that its going to reading the information instead of your server sending it.
    • [ 1 ] Thanks
  • you can use PHP.. when processing the $_POST array just first process it to your own database when you have done that make a CURL post to the other db. You don't even have to leave your url / page!
    • [ 1 ] Thanks
  • I managed to get it with this in my process.php file. and just had the form submit to it with the GET method.

    <?php
    $phone = $_GET['phone'];
    header("Location: site?=&phone=$phone");
    ?>
    <?
    $phone=$_GET['phone'];

    mysql_connect("localhost", "db_user", "db_pass) or die(mysql_error());
    mysql_select_db("db_name") or die(mysql_error());
    mysql_query("INSERT INTO `data` VALUES ('$phone')");
    Print "Your information has been successfully added to the database.";

    ?>

Next Topics on Trending Feed

  • 9

    Trying to get this form to post to my db with process.php and to another website using POST. Right now it will only load the second f.action. If I remove the first f.submit() it only does the first f.action. Any idea on getting this to work?