-1

I currently have this:

function submit()
{
    document.getElementById("lostpasswordform").click(); // Simulates button click
    document.lostpasswordform.submit(); // Submits the form without the button
}

<body onload="submit()">

    <form name="lostpasswordform" id="lostpasswordform" action="/" method="post">
        <input type="hidden" name="user_login" id="user_login" class="input" value="<?php echo ($user_login); ?>" />
    </form>

</body>

it works on PC, but for some reason, javascript is not execute from iPhone so I'm wondering if theres a way to auto-submit the form using PHP instead of JS?

Thanks

eozzy
  • 66,048
  • 104
  • 272
  • 428

5 Answers5

2

There's no way to trigger a form submission server-side. You'd have to use a language that works in the DOM like JavaScript for this one. From what you've given us, I don't see why it wouldn't work with the way you have it set up now.

Check your code and if it still doesn't work, I'd suggest asking this question in a different context; something along the lines of getting your JavaScript to work on the iPhone instead of dumping it altogether.

esqew
  • 42,425
  • 27
  • 92
  • 132
0

As esqew points out, you can't perform a client side action from the server. Your options are to rework your function so it doesn't need the autosubmit (maybe you could use a GET variable rather than posting) or finding a work around for the iPhone.

For a workaround - the .click() function doesn't work on iPhones. You could try one of the solutions that have come up from this problem before such as using tap or this larger touch handler function.

Community
  • 1
  • 1
John C
  • 8,223
  • 2
  • 36
  • 47
0

No, PHP cannot do that, but your problem is due to the way the iPhone handles click events. Here's background info and a workaround. It seems like all you need is an empty onclick function to trigger it, so:

// untested
var f = document.getElementById('lostpasswordform');
f.onclick = function () { };
document.lostpasswordform.submit();

You might want to think of the experience for a user though -- why would clicking inside a form automatically submit the form? What's wrong with a submit button?

jmdeldin
  • 5,354
  • 1
  • 28
  • 21
0

Here is a minimal javascript answer from a PHP Programmer like myself:

/** This is the script that will redraw current screen and submit to bank. */
echo '<script>'."\n" ;
echo 'function serverNotifySelected()'."\n" ;
echo '{'."\n" ;
echo '    window.open(\'\', \'BankPaymentScreen\');'."\n" ;
echo '    document.forms[\'bank_form\'].submit();'."\n" ;
echo '    document.forms[\'server_responder\'].submit();'."\n" ;
echo '}'."\n" ;
echo '</script>'."\n" ;

/** This form will be opened in a new window called BankPaymentScreen. */
echo '<form action="https://www.sandbox.bank.com/cgi-bin/webscr" name="bank_form" method="post" target="BankPaymentScreen">'."\n" ;
echo '<input type="hidden" name="cmd" value="_s-xclick">'."\n" ;
echo '<input type="hidden" name="custom" value="'.$transaction_start.'">'."\n" ;
echo '<input type="hidden" name="hosted_button_id" value="'.$single_product->hosted_button_id.'">'."\n" ;
echo '<table>'."\n" ;
echo '    <tr>'."\n";
echo '        <td><input type="hidden" name="'.$single_product->hide_name_a.'" value="'.$single_product->hide_value_a.'">Local</td>'."\n" ;
echo '    </tr>'."\n" ;
echo '    <tr>'."\n" ;
echo '        <td>'."\n" ;
echo '        <input type="hidden" name="'.$single_product->hide_name_b.'" value="'.$single_product->hide_value_b.'" />'.$single_product->short_desc.' $'.$adj_price.' USD'."\n" ;
echo '        </td>'."\n" ;
echo '    </tr>'."\n" ;
echo '</table>'."\n" ;
echo '<input type="hidden" name="currency_code" value="USD">'."\n" ;
echo '</form>'."\n" ;

/** This form will redraw the current page for approval. */
echo '<form action="ProductApprove.php" name="server_responder" method="post" target="_top">'."\n" ;
echo '<input type="hidden" name="trans" value="'.$transaction_start.'">'."\n" ;
echo '<input type="hidden" name="prod_id" value="'.$this->product_id.'">'."\n" ;
echo '</form>'."\n" ;

/** No form here just an input and a button.  onClick will handle all the forms */
echo '<input type="image" src="https://www.sandbox.bank.com/en_US/i/btn/btn_purchaseimmediateCC_LG.gif" border="0" alt="This Bank - The safer, easier way to pay!" onclick="serverNotifySelected()">'."\n" ;
echo '<img alt="" border="0" src="https://www.sandbox.bank.com/en_US/i/scr/pixel.gif" width="1" height="1">'."\n" ;

This is the code for one button. The button will redraw the current page to go from purchasing to pre-approval AND also open a new window, give the new window focus and pass the new focused window to the payment provider.

This also prevents Chrome from blocking the new page from getting focus.

user2737761
  • 115
  • 7
0

You can do this in deed.

There's an example how to, and even you can do it using cURL

<?php

//create array of data to be posted
$post_data['firstName'] = 'Name';
$post_data['action'] = 'Register';

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);

//we also need to add a question mark at the beginning of the string
$post_string = '?' . $post_string;

//we are going to need the length of the data string
$data_length = strlen($post_string);

//let's open the connection
$connection = fsockopen('www.domainname.com', 80);

//sending the data
fputs($connection, "POST  /target_url.php  HTTP/1.1\r\n");
fputs($connection, "Host:  www.domainname.com \r\n");
fputs($connection,
    "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($connection, "Content-Length: $data_length\r\n");
fputs($connection, "Connection: close\r\n\r\n");
fputs($connection, $post_string);

//closing the connection
fclose($connection);

?>