0

I want to set id of a form by php, but i can't do it!

<?php

$form= $_GET['form'];
echo"
 <form id='$form' class='thisForm form' method='post'>
    <input type ='text' name='name'/>
 </form>"; ?>

the output is :

<form id="" class="thisForm form" method="post">

I have found something, when I use inspect element of browser the id is empty string, but when use page source the id is not empty! And when I want to get the id by jQuery it is empty too!

Hamid hd
  • 103
  • 1
  • 2
  • 12

1 Answers1

1

If you are receiving any value from the get method(URL) which you want to set as id of a form then you have to assign it to a variable like

<?php
    $myid= $_GET['form']; // Any name that you want set as id.
 ?>

<form id="<?php echo $myid ?>" class="thisForm form" method="POST">
 <input type ="text" name="name"/>
</form>

So $myid variable contain a name which you're adding to your form as id.

Md. Abutaleb
  • 1,590
  • 1
  • 14
  • 24