0

Is there a way to fill a wpcf7-form, from http address...lets say by javascript. I have a form in HTML with controls in wpcf7:

<span class="wpcf7-form-control-wrap text-700">
<input class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" type="text" aria-required="true" size="30" value="" name="NameText">
</span>

For example the web page address is www.example.com/examplefrom Is there a way to auto-fill the text in textfield by running something like: www.example.com/examplefrom;javascript::getElementByID.... I'm not a web developer,but i need to solve this issue...please help

rkubic
  • 51
  • 1
  • 7

1 Answers1

0

I see your question is tagged with php. So I'll give you an option with php. First you need to check if there is POST data send in the URL

<?php
    if($_POST) {
        // Here you should take all your data and put it into a variable or an array
        $NameText = $_POST['NameText'];
        // The URL would look something like this:
        // www.example.com/exampleform?NameText=SomeText
    }
?>

Now in html you can check if the variable is empty or not and fill in the text if it is available.

<span class="wpcf7-form-control-wrap text-700">
    <input class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" type="text" aria-required="true" size="30" value="<?php echo (isset($NameText))?$NameText:''; ?>" name="NameText">
</span>

Edit: Use <?php echo (isset($NameText))?$NameText:''; ?> in each value attribute of the form fields you would like to fill with the data form the url.

Please note: This is a simple example and does not check for save post values. You should check the data if needed. But I figured there will be some security after you click the submit button of the form. So it might not be required..

Hope it helped you out.

Brainfeeder
  • 2,604
  • 2
  • 19
  • 37
  • Thanks for advice...I put in address bar link: www.example.com/exampleform?NameText=SomeText but the form is empty and there are no values in field code so...it does not work. Any other ideas? – rkubic Apr 11 '13 at 08:09
  • Do you have acces to the file to edit it ? You should add the php code in my answer to the start of your document. In the html form you should add the short php string in the value attribute of each input field you would like to see filled. (I added some info to my answer above) – Brainfeeder Apr 11 '13 at 08:16
  • OK:) I do not have acces to the file...its a autonomic webpage with a form, witch i want to fill automaticly with my values, when accesing on the page. Then a only want to click Submit button and thats all. – rkubic Apr 11 '13 at 08:33
  • Not sure how to do this in an easy way. Sorry :) But there might be a solution using cURL in php. But you will have to write some code yourself and find a place to upload it to a server which supports php :) . [a link](http://stackoverflow.com/questions/14193913/automatically-filling-out-web-forms-and-returning-the-resulting-page?rq=1) to another question on this site... – Brainfeeder Apr 11 '13 at 08:44