Jump to content

[SOLVED] Been stuck forever- passing variables between PHP and JavaScript


Recommended Posts

Jeffery, you cannot stop a php script and interact with it. Php is server side, so it will run the whole script before outputting the result to your browser. This is why you need to use a form to post the info back to the server. Use javascript and write a little function that takes your input and posts the value back to the server. You'll then run a php script to grab the posted variables and send your mail or do whatever else you want it to do.

 

What I've done in the past is to have a form in the html with some hidden values. Like:

 

<form method='post' name='myform' action='myscript.php'>
<input type='hidden' name='mycustomfield' value='' />
</form>

 

You can then take the variable in javascript and set that value before submitting the form.

 

function formSubmit(form,info){		
  form.mycustomfield.value=info;
  form.submit();
}

 

In php you grab the value of mycustomfield

$_POST['mycustomfield'];

excellent.

 

That works better, but I already just found another work around that was similar.

 

I just took the whole email routine and put it in another .php file, then had the <form> block call that .php instead of the original index.php.

Then I set all the variables as hidden variables inside the <form> and retrieved each one in the second .php script with $_POST.

 

IT worked!!!!      :P

 

 

Took me a bit of work because of all the nested quotations and whatnot........but I think we have a go. 

 

*****ISSUE RESOLVED*****

 

and who says there aren't happy endings in PHP-land?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.