Support » Plugin: Code Snippets » Custom form in WordPress, PHP in plugin

  • Resolved akmiecik

    (@akmiecik)


    Worked with the Code Snippets program yesterday, got working what I needed to get working but, this morning, site crashes when I try to save page.

    • This topic was modified 1 year ago by Yui.
    • This topic was modified 1 year ago by Steven Stern (sterndata). Reason: updated title per OP request
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter akmiecik

    (@akmiecik)

    seems like the Worpress email that notifies you the site is not working does not happen.

    Uninstalled and re-installed, no-luck. My php code was still there after re-install.

    Thread Starter akmiecik

    (@akmiecik)

    Here’s the one PHP snippet I had in there:

    function display()
    	
    {
    	$month = $_POST['month'];
    	$energy_type = $_POST['energy'];
    	$yur = $_POST['yur'];
    	$code = array (
    	'1' => 'f',
    	'2' => 'g',
    	'3' => 'h',
    	'4' => 'j',
    	'5' => 'k',
    	'6' => 'm',
    	'7' => 'n',
    	'8' => 'q',
    	'9' => 'u',
    	'10' => 'v',
    	'11' => 'x',
    	'12' => 'z');
        $suffix = $energy_type . $code[$month] . $yur;
    	$html = file_get_html("https://www.marketwatch.com/investing/future/$suffix");
    	$e = $html->find('.company__name',0);
    	$f = $html->find('.u-semi',0);
    	
    	echo $e . $f;
    
    }
    if(isset($_POST['submit']))
    {
       display();
    } 
     
     add_shortcode( 'test2', 'display' );
    
    Here's the associated Page:
    
    

    [test2]

    <form method=”post” action=””>
    Month: <select type=”text” name=”month”>
    <option value=””>Select…</option>
    <option value=”1″>January</option>
    <option value=”2″>February</option>
    <option value=”3″>March</option>
    <option value=”4″>April</option>
    <option value=”5″>May</option>
    <option value=”6″>June</option>
    <option value=”7″>July</option>
    <option value=”8″>August</option>
    <option value=”9″>September</option>
    <option value=”10″>October</option>
    <option value=”11″>November</option>
    <option value=”12″>December</option>
    </select>
    Energy Type: <select type=”text” name=”energy”>
    <option value=””>Select…</option>
    <option value=”cl”>Crude</option>
    <option value=”rb”>Gasoline</option>
    <option value=”ho”>Heating Oil</option>
    </select>
    Year: <select type=”text” name=”yur”>
    <option value=””>Select…</option>
    <option value=”21″>21</option>
    <option value=”22″>22</option>
    <option value=”23″>23</option>
    </select>
    <button type=”submit”>
    </form>`

    • This reply was modified 1 year ago by akmiecik.
    Thread Starter akmiecik

    (@akmiecik)

    Update:

    I deleted the plugin and did a little research and ended up doing my own plugin to mimic yours. I got it to work, once, then started getting crash results as I did with your plugin. So, perhaps it is something in my PHP.

    Oh, and I am using simple_html_dom which I call in the themes function.php.

    thanks

    • This reply was modified 1 year ago by akmiecik.
    Thread Starter akmiecik

    (@akmiecik)

    Just loaded a different plugin and it works.

    Thread Starter akmiecik

    (@akmiecik)

    Solution:

    I was trying to do a form by putting the form HTML into the WordPress page and rhw function code in the plugin.

    Consolidating the form HTML with the php and putting that in the plugin worked.

    Plugin Author Shea Bunge

    (@bungeshea)

    Glad to hear you managed to get things working. Please let us know if you have any follow-up questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom form in WordPress, PHP in plugin’ is closed to new replies.