Thursday, 18 April 2019

Php differentiating between javascript and user click?

I am injecting javascript into a php website to avoid a pop-up, to submit a form automatically. Also, there is an issue with jquery so I am using plain javascript.

This is the form on the page:

<form action='http://mywebsite.com/index.php?&act=MYFUNCTION&CODE=01&CookieDate=1' name='subscribe_check' method='POST'>
<input type='hidden' name='value1' value='dynamicallygenerated'>
<input type='hidden' name='Value2' value='BlogSection'>
<input type='hidden' name='Value3' value='BlogName'>
<select class='forminput' name='sub_id' onchange='this.form.submit()'>
<option value='------------' selected='selected'>To read this article, you must choose a subscription level</option>
<option value='1'>Subscribe to daily updates</option>
<option value='2'>Subscribe to promotional emails</option>
<option value='3'>No thanks, I'm not interested in being healthy</option>
</select>
</form>

This is my javascript:

  // unselect any selected item on the SELECT
  if( document.getElementsByName('subscribe_check').selectedIndex )
    document.getElementsByName('subscribe_check')[document.getElementsByName('subscribe_check').selectedIndex].selected = false;

  // select select the last option
  document.getElementsByName('subscribe_check')[1][3].selected = true;
  // submit the form
  document.forms[0].submit();

When I manually click on the form, I know that these values are set

  value1: dynamicallygenerated
  value2: HealthyFoodSection
  value3: HealthyFoodFunBlog

But when my javascript submits the form, these values are submitted

  value1: dynamicallygenerated
  value2: BlogSection
  value3: BlogName

I am 100% sure there is no other javascript that is firing to change the values - there can't be, the onchange calls submit() directly.

I don't understand why my javascript submitting the form doesn't change the values like clicking it manually does? If there is PHP happening, I don't understand how it would even detect that my javascript submitted the form verus me clicking submit, a submit click is a submit click, right?



from Php differentiating between javascript and user click?

No comments:

Post a Comment