4 Replies - 907 Views - Last Post: 25 February 2014 - 05:54 AM Rate Topic: -----

#1 lolspy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-February 14

how this code can write and execute using php?

Posted 25 February 2014 - 04:44 AM

how this code can write and execute using php?

<script type="text/javascript">
function myFunction()
{
var str = value = document.getElementById('page').value; // The input
var res = str.substring(0,1); // The first 1 characters
if(res == "1") {
    window.open("1.html","_self");
}
var str = value = document.getElementById('page').value; // The input
var res = str.substring(0,5); // The first 5 characters
if(res == "12345") {
    window.open("12345.html","_self");
}
var str = value = document.getElementById('page').value; // The input
var res = str.substring(0,3); // The first 3 characters
if(res == "123") {
    window.open("123.html","_self");
}
var str = value = document.getElementById('page').value; // The input
var res = str.substring(0,1); // The first 1 characters
if(res == "3") {
    window.open("3.html","_self");
}
}
</script>



Is This A Good Question/Topic? 0
  • +

Replies To: how this code can write and execute using php?

#2 Ntwiles   User is offline

  • D.I.C Addict

Reputation: 148
  • View blog
  • Posts: 831
  • Joined: 26-May 10

Re: how this code can write and execute using php?

Posted 25 February 2014 - 04:54 AM

  • We are not here to convert your code for you. Do it yourself, and we'll be glad to help if you hit any roadblocks.
  • This code should not be converted to PHP, it's a job meant for a client-side scripting language. You could so something similar using PHP POST data and its header() function though.

This post has been edited by Ntwiles: 25 February 2014 - 04:57 AM

Was This Post Helpful? 0
  • +
  • -

#3 lolspy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 23
  • Joined: 12-February 14

Re: how this code can write and execute using php?

Posted 25 February 2014 - 05:03 AM

View PostNtwiles, on 25 February 2014 - 04:54 AM, said:

    Why do you want to write this in PHP?


I wanted to sign this code in php, because I have a html form which has to meet both the php and the javascript at the same time. But typing form action = "test.php" and onclick = "MyFunction ()" I have nothing worked. This is probably because at javascript using window.open.
I do not know how to set up to pressing submit my form satisfying both the php and the javascript at the same time. so I think the javascript code could be rewritten to php
Was This Post Helpful? 0
  • +
  • -

#4 Ntwiles   User is offline

  • D.I.C Addict

Reputation: 148
  • View blog
  • Posts: 831
  • Joined: 26-May 10

Re: how this code can write and execute using php?

Posted 25 February 2014 - 05:12 AM

You're right, you want PHP to get the form data, handle it, THEN redirect the user to the next page. The two links I gave you above should help you with that. Send the data to your php page via POST (or GET), handle the form data how you normally would, then redirect using the header() function.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4287
  • View blog
  • Posts: 13,591
  • Joined: 08-June 10

Re: how this code can write and execute using php?

Posted 25 February 2014 - 05:54 AM

Quote

I wanted to sign this code in php, because I have a html form which has to meet both the php and the javascript at the same time.

not possible, because
- PHP is a server-side language, Java­Script is a client-side language
- even if you could (for whatever reason) run it at the same time, you would create a Race Condition

Java­Script validation is meant to be a user aid to produce an as valid as possible dataset for processing on the server. Nevertheless, no matter how good your client-side validation is, you must always and completely validate your data on the server-side. bear in mind that your web page is not the only User Agent that can send data to your server script*.


* - e.g. form (POST) submit via cURL: curl -d 'key=value&otherkey=someothervalue' http://example.com/yourscript.php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1